List of usage examples for java.awt Container setLayout
public void setLayout(LayoutManager mgr)
From source file:BoxLayoutYAXISTest.java
public static void main(String[] args) { JFrame f = new JFrame("Vertical BoxLayout-managed container"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); for (float align = 0.0f; align <= 1.0f; align += 0.25f) { JButton button = new JButton("X Alignment = " + align); button.setAlignmentX(align);//from ww w . java 2 s.co m pane.add(button); } f.setSize(400, 300); f.setVisible(true); }
From source file:GridBagLayoutFill.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0;/*w w w . j av a 2 s . c o m*/ gbc.gridy = GridBagConstraints.RELATIVE; pane.add(new JButton("This button's preferred width " + "is large because its text is long"), gbc); pane.add(new JButton("Small centered button"), gbc); gbc.fill = GridBagConstraints.HORIZONTAL; pane.add(new JButton("Expands to fill column width"), gbc); f.setSize(400, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container content = frame.getContentPane(); content.setLayout(new GridLayout(0, 2)); JTextArea leftTextArea = new JTextArea(); content.add(leftTextArea);// ww w . ja va 2 s .com leftTextArea.paste(); frame.setSize(250, 150); frame.setVisible(true); }
From source file:RelativeXY.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 1;/*from w ww. j a v a2 s. c om*/ gbc.gridy = GridBagConstraints.RELATIVE; pane.add(new JButton("First row, first column"), gbc); pane.add(new JButton("Second row"), gbc); pane.add(new JButton("Third row"), gbc); gbc.gridx = GridBagConstraints.RELATIVE; pane.add(new JButton("First row, second column"), gbc); f.setSize(500, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame aWindow = new JFrame(); aWindow.setBounds(200, 200, 200, 200); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = aWindow.getContentPane(); content.setLayout(new FlowLayout(FlowLayout.LEFT)); content.add(new JButton("www.java2s.com")); content.add(new JLabel("www.java2s.com")); content.add(new JTextField("www.java2s.com")); aWindow.setVisible(true);/*from ww w . jav a 2s. com*/ }
From source file:TryGridLayout.java
public static void main(String[] args) { JFrame aWindow = new JFrame("This is a Grid Layout"); aWindow.setBounds(30, 30, 300, 300); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GridLayout grid = new GridLayout(3, 4, 30, 20); Container content = aWindow.getContentPane(); content.setLayout(grid); JButton button = null;/*from w w w .j a v a 2s .com*/ for (int i = 1; i <= 10; i++) { content.add(button = new JButton(" Press " + i)); } aWindow.pack(); aWindow.setVisible(true); }
From source file:SpinnerDemo.java
public static void main(String[] args) { JFrame jf = new JFrame("It Spins"); Container cp = jf.getContentPane(); cp.setLayout(new GridLayout(0, 1)); // Create a JSpinner using one of the pre-defined SpinnerModels JSpinner dates = new JSpinner(new SpinnerDateModel()); cp.add(dates);//from w ww .j a v a2 s. c om // Create a JSPinner using a SpinnerListModel. String[] data = { "One", "Two", "Three" }; JSpinner js = new JSpinner(new SpinnerListModel(data)); cp.add(js); jf.setSize(100, 80); jf.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String title = "GridBagLayout"; JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridBagLayout()); for (int i = 1; i <= 9; i++) { contentPane.add(new JButton("Button " + i)); }/*w w w.ja v a 2 s . c o m*/ frame.pack(); frame.setVisible(true); }
From source file:GridBagLayoutRemainder.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); pane.add(new JButton("First row, first column"), gbc); pane.add(new JButton("First row, second column"), gbc); pane.add(new JButton("First row, third column"), gbc); gbc.gridx = 0;/* w w w . ja v a 2s . c o m*/ pane.add(new JButton("Second row"), gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.HORIZONTAL; pane.add(new JButton("Third row, gridwidth set to REMAINDER"), gbc); f.setSize(600, 300); f.setVisible(true); }
From source file:ButtonFocus.java
public static void main(String args[]) { JFrame frame = new JFrame("Action Sample"); JButton focusButton = new JButton("Focused"); JButton notFocusButton = new JButton("Not Focused"); Container contentPane = frame.getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(focusButton);/* w w w. j ava 2s . co m*/ contentPane.add(notFocusButton); frame.setSize(300, 100); frame.setVisible(true); }