「swing-JFrame」の編集履歴(バックアップ)一覧はこちら
swing-JFrame - (2008/10/29 (水) 18:08:12) の1つ前との変更点
追加された行は緑色になります。
削除された行は赤色になります。
*Swing JFrame
トップレベルコンテナ
JFrameサンプル
import javax.swing.*;
public class TestFrame {
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Test1 --- Kitty");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
//JLabel label = new JLabel("Hello World");
//frame.getContentPane().add(label);
JButton bt1 = new JButton("Push me!");
frame.getContentPane().add(bt1);
//Display the window.
frame.setBounds(0 , 0 , 400 , 200);
//frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
1.frame.setDefaultCloseOperation()
ウィンドウ終了動作
-DO_NOTHING_ON_CLOSE :何もしない
-HIDE_ON_CLOSE :非表示
-DISPOSE_ON_CLOSE :破棄
-EXIT_ON_CLOSE :アプリ終了
2.setBounds()
ウィンドウサイズ
3.pack()
ウィンドウサイズを中に表示するコンポーネントにあわせて最適化(最小化)する。
*Swing JFrame
トップレベルコンテナ
JFrameサンプル
import javax.swing.*;
public class TestFrame {
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Test1 --- Kitty");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
//JLabel label = new JLabel("Hello World");
//frame.getContentPane().add(label);
JButton bt1 = new JButton("Push me!");
frame.getContentPane().add(bt1);
//Display the window.
frame.setBounds(0 , 0 , 400 , 200);
//frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
1.frame.setDefaultCloseOperation()
ウィンドウ終了動作
-DO_NOTHING_ON_CLOSE :何もしない
-HIDE_ON_CLOSE :非表示
-DISPOSE_ON_CLOSE :破棄
-EXIT_ON_CLOSE :アプリ終了
2.setBounds()
ウィンドウサイズ
3.pack()
ウィンドウサイズを中に表示するコンポーネントにあわせて最適化(最小化)する。
表示オプション
横に並べて表示:
変化行の前後のみ表示: