List of usage examples for javax.swing JFrame setLayout
public void setLayout(LayoutManager manager)
LayoutManager
. From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl); JButton component = new JButton("1"); frame.add(component);/*from ww w.j av a 2 s.co m*/ frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.NONE; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl); JButton component = new JButton("1"); frame.add(component);// w ww.j a va2 s .c om frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.weightx = 1; gbc.weighty = 2; gbl.setConstraints(component, gbc); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl); JButton component = new JButton("1"); frame.add(component);/*from ww w . j a v a 2 s . c o m*/ frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.VERTICAL; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl); JButton component = new JButton("1"); frame.add(component);//from w w w . j a va2 s. c om frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl); JButton component = new JButton("1"); frame.add(component);//from w w w .j av a 2 s. c om frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); }
From source file:ButtonModel.java
public static void main(String[] args) { final JButton ok = new JButton("ok"); JCheckBox cb = new JCheckBox("Enabled", true); ok.setBounds(40, 30, 80, 25);//from w w w . j av a 2 s.c om ok.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { DefaultButtonModel model = (DefaultButtonModel) ok.getModel(); if (model.isEnabled()) System.out.println("Enabled: true"); else System.out.println("Enabled: false"); if (model.isArmed()) System.out.println("Armed: true"); else System.out.println("Armed: false"); if (model.isPressed()) System.out.println("Pressed: true"); else System.out.println("Pressed: false"); } }); cb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (ok.isEnabled()) ok.setEnabled(false); else ok.setEnabled(true); } }); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(ok); f.add(cb); f.setSize(350, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl); frame.add(new JButton("1")); frame.add(new JButton("2")); gbl.layoutContainer(frame);//w w w.j a va 2 s.c om double[][] weights = gbl.getLayoutWeights(); for (int i = 0; i < 2; i++) { for (int j = 0; j < weights[i].length; j++) { weights[i][j] = 1; } } gbl.columnWeights = weights[0]; gbl.rowWeights = weights[1]; frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JDesktopPane dp = new JDesktopPane(); JInternalFrame inf = new JInternalFrame("Help", true, true, true, true); inf.setSize(200, 200);/*from www . ja v a 2 s . c om*/ inf.setVisible(true); dp.add(inf); JButton btn = new JButton("Click"); btn.addActionListener(e -> JOptionPane.showInternalInputDialog(inf, "Hit me")); inf.add(btn); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new BorderLayout()); f.add(dp); f.setSize(400, 400); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl); JButton component = new JButton("1"); frame.add(component);//ww w. j ava 2s. c o m frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); // Make the component on stretchable gbc.fill = GridBagConstraints.NONE; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel northPanel = new JPanel(new GridLayout(2, 1)); JPanel welcomePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); welcomePanel.add(new JLabel("Welcome")); northPanel.add(welcomePanel);/* www. j ava 2 s . c om*/ JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JRadioButton button1 = new JRadioButton("Button 1", true); JRadioButton button2 = new JRadioButton("Button 2", false); ButtonGroup group = new ButtonGroup(); group.add(button1); group.add(button2); radioPanel.add(button1); radioPanel.add(button2); northPanel.add(radioPanel); JPanel middlePanel = new JPanel(new GridLayout(3, 3)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { middlePanel.add(new JButton("Button " + i + j)); } } JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); southPanel.add(new JLabel("Whose turn:")); southPanel.add(new JButton("Reset")); frame.add(northPanel, BorderLayout.NORTH); frame.add(middlePanel, BorderLayout.CENTER); frame.add(southPanel, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }