post #1 of 1
Thread Starter 
I was having spacing issues for some of the components because the layout manager automatically determines the column widths. I wanted to group some components in different rows together without stretching them horizontally. The method I used to shrink unwanted space between components was to use the same preferred width for every component in column 0 for instance, which effectively resized the column. Unfortunately this leads to other problems. For now I will be using abs positioning until I can find a better solution using layout managers.
Code:
JPanel p = new JPanel(new GridBagLayout());

GridBagConstraints c = new GridBagConstraints();
                
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.weightx = 0.0;
c.weighty = 1.0;
                
JButton btn1 = new JButton("button");
btn1.setPreferredSize(new Dimension(75, 25));
c.gridx = 0;
c.gridy = 0;
p.add(btn1, c);
                
c.insets = new Insets(0, 35, 0, 0);
c.weightx = 1.0;
c.weighty = 0.0;
JButton btn2 = new JButton("button");
c.gridx = 1;
c.gridy = 0;
p.add(btn2, c);
                
c.insets = new Insets(0, 0, 0, 0);
c.weightx = 0.0;
c.weighty = 1.0;
JButton btn3 = new JButton("button");
btn3.setPreferredSize(new Dimension(75, 25));
c.gridx = 0;
c.gridy = 1;
p.add(btn3, c);
                
JButton btn4 = new JButton("button");
c.gridx = 1;
c.gridy = 1;
p.add(btn4, c);

Edited by darkpside - 4/5/13 at 9:53pm