-4

Java レイアウトを理解しようとしていますが、フレームが表示されませんでした。何が間違っていますか。助けていただけますか?

public class NewClass {
      NewClass(){
          JFrame f=new JFrame();
          JPanel jPanelcolor=new JPanel();
          JPanel jPanelLayout=new JPanel( new GridLayout(3,3));
          JTextField fieldred=new JTextField();

         JSlider jsred=new JSlider();
         JSlider jsgreen=new JSlider();
         JSlider jsblue=new JSlider();
         jPanelLayout.add(new JLabel("Red"));
         jPanelLayout.add(jsred);
         jPanelLayout.add(fieldred);
         f.getContentPane().add(jPanelcolor, BorderLayout.CENTER);
         f.getContentPane().add(jPanelcolor, BorderLayout.SOUTH);
         f.setVisible(true);
     }

     public static void main(String[]args){
         new NewClass();
     }
4

1 に答える 1

3

The two main problems are that

  • you're adding the same jPanelcolor, containing nothing, twice in the same frame content pane
  • you don't call pack() before making the frame visible, to make it have the most appropriate dimension based on the components it contains.

Another problem is that you don't respect the Swing threading rules.

于 2013-07-12T17:02:09.817 に答える