Results 1 to 2 of 2
Thread: GridBagLayout
- 01-15-2009, 03:17 PM #1
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
- 01-15-2009, 08:54 PM #2
Java Code:import java.awt.*; import javax.swing.*; public class GridBagDemo { private JPanel getContent() { JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(5,5,5,5); gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; panel.add(getPanel1(), gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; panel.add(getPanel2(), gbc); gbc.gridwidth = 2; panel.add(getPanel3(), gbc); return panel; } private JPanel getPanel1() { JButton button = new JButton("button"); JTextArea textArea = new JTextArea(4, 20); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.insets.bottom = 10; panel.add(button, gbc); gbc.insets.bottom = 0; panel.add(textArea, gbc); return panel; } private JPanel getPanel2() { JButton button = new JButton("button"); JTextArea textArea = new JTextArea(4, 20); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); panel.add(textArea, gbc); gbc.anchor = GridBagConstraints.NORTH; gbc.insets.left = 10; panel.add(button, gbc); return panel; } private JPanel getPanel3() { JButton button = new JButton("button"); JTextArea textArea = new JTextArea(4, 20); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridwidth = GridBagConstraints.REMAINDER; panel.add(textArea, gbc); gbc.insets = new Insets(5,5,5,5); gbc.fill = GridBagConstraints.NONE; panel.add(button, gbc); return panel; } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new GridBagDemo().getContent()); f.pack(); f.setLocation(200,200); f.setVisible(true); } }
Similar Threads
-
abt gridbaglayout
By pinky in forum AWT / SwingReplies: 1Last Post: 12-15-2008, 08:35 AM -
GridBagLayout
By newtojava7 in forum New To JavaReplies: 2Last Post: 03-07-2008, 12:16 AM -
GridBagLayout...please help
By newtojava7 in forum Advanced JavaReplies: 1Last Post: 02-17-2008, 01:16 AM -
gridbaglayout
By newtojava7 in forum New To JavaReplies: 4Last Post: 01-27-2008, 08:03 PM -
Problem with GridBagLayout
By Daniel in forum SWT / JFaceReplies: 2Last Post: 07-01-2007, 06:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks