List of usage examples for javax.swing JFrame JFrame
public JFrame(String title) throws HeadlessException
Frame
with the specified title. From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.LINE_AXIS); container.setLayout(layout);// ww w .ja v a2 s.c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("GroupLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); GroupLayout groupLayout = new GroupLayout(contentPane); contentPane.setLayout(groupLayout);// w w w . j a v a 2s . c om JLabel label = new JLabel("Label"); JButton b2 = new JButton("Second Button"); groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup().addComponent(label).addComponent(b2)); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label).addComponent(b2)); frame.pack(); frame.setVisible(true); }
From source file:UsingWindowListener.java
public static void main(String[] args) { JFrame aWindow = new JFrame("This is the Window Title"); aWindow.setBounds(50, 100, 300, 300); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); aWindow.addWindowListener(new WindowListener() { public void windowIconified(WindowEvent e) { System.out.println(e); }//from w w w . ja va2 s . c o m public void windowDeiconified(WindowEvent e) { } public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { } public void windowClosed(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } }); aWindow.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setAccelerator(KeyStroke.getKeyStroke("F")); // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New"); fileMenu.add(newMenuItem);/*from w w w. j a v a 2s . c om*/ frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); System.out.println(layout.preferredLayoutSize(container)); container.setLayout(layout);//from www . j a va 2 s. c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); System.out.println(layout.getLayoutAlignmentY(container)); container.setLayout(layout);//from w w w . jav a 2s .co m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); System.out.println(layout.getLayoutAlignmentX(container)); container.setLayout(layout);//from w w w.j av a2 s.co m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); System.out.println(layout.getTarget()); container.setLayout(layout);// ww w.j a v a 2 s .c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); layout.invalidateLayout(container);/*from w w w. j ava2 s. co m*/ container.setLayout(layout); for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:AlignY.java
public static void main(String args[]) { JFrame frame = new JFrame("Y Alignment"); JPanel contentPane = (JPanel) frame.getContentPane(); BoxLayout layout = new BoxLayout(contentPane, BoxLayout.X_AXIS); contentPane.setLayout(layout);// w w w. j a v a2 s. c o m JButton button = new JButton("0.0"); button.setAlignmentY(Component.TOP_ALIGNMENT); contentPane.add(button); button = new JButton("1.0"); button.setAlignmentY(Component.BOTTOM_ALIGNMENT); contentPane.add(button); button = new JButton("0.5"); button.setAlignmentY(Component.CENTER_ALIGNMENT); contentPane.add(button); frame.setSize(200, 100); frame.show(); }