List of usage examples for java.awt Insets Insets
public Insets(int top, int left, int bottom, int right)
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.setMargin(new Insets(5, 5, 5, 5)); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb);/*from w ww . j a v a2 s . c o m*/ f.pack(); f.setVisible(true); }
From source file:RigidArea.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setBorder(new EmptyBorder(new Insets(40, 60, 40, 60))); panel.add(new JButton("Button")); panel.add(Box.createRigidArea(new Dimension(0, 5))); panel.add(new JButton("Button")); panel.add(Box.createRigidArea(new Dimension(0, 5))); panel.add(new JButton("Button")); panel.add(Box.createRigidArea(new Dimension(0, 5))); panel.add(new JButton("Button")); JFrame f = new JFrame(); f.add(panel);/*from w w w .j a v a 2s .c o m*/ f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:BorderExample.java
public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); JPanel top = new JPanel(); top.setBackground(Color.gray); top.setPreferredSize(new Dimension(250, 150)); panel.add(top);//from www . j a v a 2 s . c o m panel.setBorder(new EmptyBorder(new Insets(10, 20, 30, 40))); JFrame f = new JFrame(); f.add(panel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JSpinner spinner = new JSpinner(); // Get the text field JFormattedTextField tf = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField(); // Set the margin (add two spaces to the left and right side of the value) int top = 0;// w w w . j a va 2 s .c o m int left = 2; int bottom = 0; int right = 2; Insets insets = new Insets(top, left, bottom, right); tf.setMargin(insets); }
From source file:GridBagWithWeight.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of fill constraints"); JPanel p = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.weighty = 1.0;/*from w w w . j a v a2 s .c o m*/ c.weightx = 1.0; c.gridx = 0; c.gridy = 0; c.gridheight = 2; c.fill = GridBagConstraints.BOTH; // Use both horizontal & vertical p.add(new JButton("Java"), c); c.gridx = 1; c.gridheight = 1; c.gridwidth = 2; c.fill = GridBagConstraints.HORIZONTAL; // Horizontal only p.add(new JButton("Source"), c); c.gridy = 1; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; // Remember to reset to none p.add(new JButton("and"), c); c.gridx = 2; c.fill = GridBagConstraints.VERTICAL; // Vertical only p.add(new JButton("Support."), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:GridBagWithGridWidthHeight.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of gridwidth, gridheight constraints"); JPanel p = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.weighty = 1.0;//from w w w .j a va2 s . c o m c.weightx = 1.0; c.gridx = 0; c.gridy = 0; c.gridheight = 2; // span across 2 rows p.add(new JButton("Java"), c); c.gridx = 1; c.gridheight = 1; // set back to 1 row c.gridwidth = 2; // span across 2 columns p.add(new JButton("Source"), c); c.gridy = 1; c.gridwidth = 1; // set back to 1 column p.add(new JButton("and"), c); c.gridx = 2; p.add(new JButton("Support."), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame(Main.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel btmPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.weighty = 1.0;/*from w w w . ja v a 2s .com*/ gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(5, 5, 5, 5); gbc.anchor = GridBagConstraints.NORTH; JButton comp = new JButton("Panel-1"); btmPanel.add(comp, gbc); JButton comp2 = new JButton("Panel-2"); btmPanel.add(comp2, gbc); JButton comp3 = new JButton("Panel-3"); comp3.setPreferredSize(new Dimension(comp.getPreferredSize().width, comp.getPreferredSize().height + 10)); btmPanel.add(comp3, gbc); frame.add(btmPanel); frame.pack(); frame.setVisible(true); }
From source file:GridBagWithAnchor.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of anchor constraints"); JPanel p = new JPanel(new GridBagLayout()); p.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.weighty = 1.0;// w w w.j a v a 2 s . c om c.weightx = 1.0; c.gridx = 0; c.gridy = 0; c.gridheight = 2; c.anchor = GridBagConstraints.NORTH; // place component on the North p.add(new JButton("Java"), c); c.gridx = 1; c.gridheight = 1; c.gridwidth = 2; c.anchor = GridBagConstraints.SOUTHWEST; p.add(new JButton("Source"), c); c.gridy = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.CENTER; // remember to rest to center p.add(new JButton("and"), c); c.gridx = 2; p.add(new JButton("Support !!!"), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:GridBagWithContaints.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of gridx, gridy,ipadx, ipady and insets constraints"); JPanel p = new JPanel(); p.setLayout(new GridBagLayout()); // creates a constraints object GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); // insets for all components c.gridx = 0; // column 0 c.gridy = 0; // row 0 c.ipadx = 5; // increases components width by 10 pixels c.ipady = 5; // increases components height by 10 pixels p.add(new JButton("Java"), c); // constraints passed in c.gridx = 1; // column 1 // c.gridy = 0; // comment out this for reusing the obj c.ipadx = 0; // resets the pad to 0 c.ipady = 0;/* w w w. j a v a2s . co m*/ p.add(new JButton("Source"), c); c.gridx = 0; // column 0 c.gridy = 1; // row 1 p.add(new JButton("and"), c); c.gridx = 1; // column 1 p.add(new JButton("Support."), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JToolBar toolbar = new JToolBar(); ImageIcon icon = new ImageIcon("icon.gif"); Action action = new AbstractAction("Button Label", icon) { public void actionPerformed(ActionEvent evt) { }//w w w .j ava2 s .co m }; JButton c1 = new JButton(action); c1.setText(null); c1.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c1); JToggleButton c2 = new JToggleButton(action); c2.setText(null); c2.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c2); JComboBox c3 = new JComboBox(new String[] { "A", "B", "C" }); c3.setPrototypeDisplayValue("XXXXXXXX"); // Set a desired width c3.setMaximumSize(c3.getMinimumSize()); toolbar.add(c3); }