2016-07-25 5 views
1

IntelliJのGUI機能を使用していますが、フレームを表示するのに苦労しています。ここでGUIでフレームを表示する方法

は私のGUIコンポーネントの絵です:

public class SftpDoc extends JPanel{ 

private JRadioButton radioButton1; 
private JRadioButton radioButton2; 
private JRadioButton radioButton3; 
private JButton button1; 
private JComboBox comboBox1; 
private JTextField textField1; 
private JButton browseButton; 
private JButton button2; 
private final static JPanel panel = new JPanel(); 

public SftpDoc(){ 

    panel.add(button1); 
    panel.add(comboBox1); 
    panel.add(radioButton1); 
    panel.add(textField1); 
    panel.add(browseButton); 
    panel.add(radioButton2); 
    panel.add(radioButton3); 
    panel.add(button2); 

} 

public static void main(String[] args) { 

    SwingUtilities.invokeLater(new Runnable() { 
     public void run() { 
      JFrame frame = new JFrame(); 
      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
      frame.getContentPane().add(panel); 
      frame.setVisible(true); 

     } 
    }); 

} 
} 

私はクラスにフレームを実行すると:

enter image description here

そして、ここでは、私は私のIDEでそれを設定するために使用するコードです表示される唯一のコンポーネントです: enter image description here

答えて

0

ウィンドウを最大化するか、フレームを設定してみてくださいeのコードで - frame.setSize()

+0

frame.pack()を使用すると、フレーム内のコンポーネントのサイズに応じて自動的にフレームのサイズが変更されます。 – Michael

+0

ご意見ありがとうございます。私はそれを追加しようとしましたが、それはまだフレーム内に何もないことを示しています。 – Hendrien

0

私はそれを実行し、すべてを表示することができました。 JPanelを拡張する代わりに、私はJFrameを使用し、クラスを可視に設定するよう呼びました。コードは以下の通りです:

public class SftpDoc extends JFrame { 

private JRadioButton radioButton1; 
private JRadioButton radioButton2; 
private JRadioButton radioButton3; 
private JButton button1; 
private JComboBox comboBox1; 
private JTextField textField1; 
private JButton browseButton; 
private JButton button2; 
private final static JPanel panel = new JPanel(); 

public SftpDoc() { 

    panel.add(button1); 
    panel.add(comboBox1); 
    panel.add(radioButton1); 
    panel.add(textField1); 
    panel.add(browseButton); 
    panel.add(radioButton2); 
    panel.add(radioButton3); 
    panel.add(button2); 
    panel.revalidate(); 
    add(panel); 
    pack(); 
} 

public static void main(String[] args) { 

    SwingUtilities.invokeLater(new Runnable() { 
     public void run() { 
      new SftpDoc().setVisible(true); 
     } 
    }); 

} 
} 
0
frame.getContentPane().add(panel); 
frame.pack(); 
frame.setVisible(true); 

こんにちは、あなたは(frame.packを追加する必要があります)。 setVisible()メソッドの前。

関連する問題