List of usage examples for java.awt GridBagLayout setConstraints
public void setConstraints(Component comp, GridBagConstraints constraints)
From source file:Main.java
private void addButton(String label, GridBagConstraints constraints, GridBagLayout layout) { Border edge = BorderFactory.createRaisedBevelBorder(); JButton button = new JButton(label); button.setBorder(edge);//from w w w. jav a2 s .c o m layout.setConstraints(button, constraints); add(button); }
From source file:SimpleAuthenticator.java
private Component constrain(Component cmp, GridBagLayout gb, GridBagConstraints c) { gb.setConstraints(cmp, c); return (cmp); }
From source file:MainClass.java
public MainClass() { super("Clipboard Test"); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag);//ww w.j a v a 2 s.co m srcText = new TextArea(8, 32); c.gridwidth = 2; c.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(srcText, c); add(srcText); copyButton = new Button("Copy Above"); copyButton.setActionCommand("copy"); copyButton.addActionListener(this); c.gridy = 1; c.gridwidth = 1; gridbag.setConstraints(copyButton, c); add(copyButton); pasteButton = new Button("Paste Below"); pasteButton.setActionCommand("paste"); pasteButton.addActionListener(this); pasteButton.setEnabled(false); c.gridx = 1; gridbag.setConstraints(pasteButton, c); add(pasteButton); dstText = new TextArea(8, 32); c.gridx = 0; c.gridy = 2; c.gridwidth = 2; gridbag.setConstraints(dstText, c); add(dstText); pack(); }
From source file:ClipboardTest.java
public ClipboardTest() { super("Clipboard Test"); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag);//w ww.jav a 2 s .c o m srcText = new TextArea(8, 32); c.gridwidth = 2; c.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(srcText, c); add(srcText); copyButton = new Button("Copy Above"); copyButton.setActionCommand("copy"); copyButton.addActionListener(this); c.gridy = 1; c.gridwidth = 1; gridbag.setConstraints(copyButton, c); add(copyButton); pasteButton = new Button("Paste Below"); pasteButton.setActionCommand("paste"); pasteButton.addActionListener(this); pasteButton.setEnabled(false); c.gridx = 1; gridbag.setConstraints(pasteButton, c); add(pasteButton); dstText = new TextArea(8, 32); c.gridx = 0; c.gridy = 2; c.gridwidth = 2; gridbag.setConstraints(dstText, c); add(dstText); pack(); }
From source file:MultiListener.java
public MultiListener() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); JLabel l = null;/*from www.j a v a 2 s.c o m*/ c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; l = new JLabel("What MultiListener hears:"); gridbag.setConstraints(l, c); add(l); c.weighty = 1.0; topTextArea = new JTextArea(); topTextArea.setEditable(false); JScrollPane topScrollPane = new JScrollPane(topTextArea); Dimension preferredSize = new Dimension(200, 75); topScrollPane.setPreferredSize(preferredSize); gridbag.setConstraints(topScrollPane, c); add(topScrollPane); c.weightx = 0.0; c.weighty = 0.0; l = new JLabel("What Eavesdropper hears:"); gridbag.setConstraints(l, c); add(l); c.weighty = 1.0; bottomTextArea = new JTextArea(); bottomTextArea.setEditable(false); JScrollPane bottomScrollPane = new JScrollPane(bottomTextArea); bottomScrollPane.setPreferredSize(preferredSize); gridbag.setConstraints(bottomScrollPane, c); add(bottomScrollPane); c.weightx = 1.0; c.weighty = 0.0; c.gridwidth = 1; c.insets = new Insets(10, 10, 0, 10); button1 = new JButton("Blah blah blah"); gridbag.setConstraints(button1, c); add(button1); c.gridwidth = GridBagConstraints.REMAINDER; button2 = new JButton("You don't say!"); gridbag.setConstraints(button2, c); add(button2); button1.addActionListener(this); button2.addActionListener(this); button2.addActionListener(new Eavesdropper(bottomTextArea)); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 1, 2, 2, Color.black), BorderFactory.createEmptyBorder(5, 5, 5, 5))); }
From source file:events.TreeExpandEventDemo.java
public TreeExpandEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0;//from w w w . j ava 2 s. co m c.weighty = 1.0; c.insets = new Insets(1, 1, 1, 1); demoArea = new DemoArea(); gridbag.setConstraints(demoArea, c); add(demoArea); c.insets = new Insets(0, 0, 0, 0); textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(200, 75)); gridbag.setConstraints(scrollPane, c); add(scrollPane); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:width.java
public void init() { GridBagLayout gridBag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridBag);//from w w w . ja v a 2 s . co m Label receiverLabel = new Label("Receiver name:", Label.RIGHT); gridBag.setConstraints(receiverLabel, c); add(receiverLabel); nameField = new TextField(getParameter("RECEIVERNAME"), 10); c.fill = GridBagConstraints.HORIZONTAL; gridBag.setConstraints(nameField, c); add(nameField); nameField.addActionListener(this); Button button = new Button("Send message"); c.gridwidth = GridBagConstraints.REMAINDER; //end row c.anchor = GridBagConstraints.WEST; //stick to the //text field c.fill = GridBagConstraints.NONE; //keep the button //small gridBag.setConstraints(button, c); add(button); button.addActionListener(this); status = new TextArea(5, 60); status.setEditable(false); c.anchor = GridBagConstraints.CENTER; //reset to the default c.fill = GridBagConstraints.BOTH; //make this big c.weightx = 1.0; c.weighty = 1.0; gridBag.setConstraints(status, c); add(status); myName = getParameter("NAME"); Label senderLabel = new Label("(My name is " + myName + ".)", Label.CENTER); c.weightx = 0.0; c.weighty = 0.0; gridBag.setConstraints(senderLabel, c); add(senderLabel); newline = System.getProperty("line.separator"); }
From source file:SwingMouseMotionEventDemo.java
public SwingMouseMotionEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0;// w w w . j av a 2s . c o m c.weighty = 1.0; c.insets = new Insets(1, 1, 1, 1); blankArea = new BlankArea(new Color(0.98f, 0.97f, 0.85f)); gridbag.setConstraints(blankArea, c); add(blankArea); c.insets = new Insets(0, 0, 0, 0); textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setPreferredSize(new Dimension(200, 75)); gridbag.setConstraints(scrollPane, c); add(scrollPane); //Register for mouse events on blankArea and panel. blankArea.addMouseMotionListener(this); addMouseMotionListener(this); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:MouseEventDemo.java
public MouseEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0;/*from w w w . j a v a 2s .c o m*/ c.weighty = 1.0; c.insets = new Insets(1, 1, 1, 1); blankArea = new BlankArea(new Color(0.98f, 0.97f, 0.85f)); gridbag.setConstraints(blankArea, c); add(blankArea); c.insets = new Insets(0, 0, 0, 0); textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(200, 75)); gridbag.setConstraints(scrollPane, c); add(scrollPane); //Register for mouse events on blankArea and the panel. blankArea.addMouseListener(this); addMouseListener(this); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:TreeExpandEventDemo2.java
public TreeExpandEventDemo2() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0;//from w w w . j ava 2 s. c o m c.weighty = 1.0; c.insets = new Insets(1, 1, 1, 1); demoArea = new DemoArea(); gridbag.setConstraints(demoArea, c); add(demoArea); c.insets = new Insets(0, 0, 0, 0); textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(200, 75)); gridbag.setConstraints(scrollPane, c); add(scrollPane); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }