Article View: borland.public.jbuilder.java.swing
Article #9855Re: Help with GridBagLayout manager
From: Jeff Marendo
Date: Tue, 11 Jan 2000 00:00
Date: Tue, 11 Jan 2000 00:00
173 lines
8506 bytes
8506 bytes
Hi Paul,
Thanks for the reply and the info. I posted my latest code for my design
below if you have some time to look at it. I have three JPanels for all of
this. I'm using the GridBagLayout manager for all three panels.
Originally, I laid out everything in each panel using XYLayout. I converted
the two inner panels (with all of my components) first to GridBagLayout and
then I converted the main panel; but, when I did that, the placement of the
two inner panels got pretty messed up. So, I set the main panel back to
XYLayout and just dragged the two inner panels closer together (vertically).
In any event, this is the closest I can get to what I want. The alignment
of the starting components in each panel are still just a bit off. Also, if
I enlarge the window when it's running, the space between the bottom and top
panels expands. I'm not sure why that is, but I think each panel starts to
grab the extra space of the main panel. Ideally, I'd like to keep the
panels looking like two rows that come right after the other. Let me know
if you find anything interesting or have any suggestions. Thanks.
Jeff
ps. Do you know if the GridBagLayout manager's default behavior when making
a window smaller (by dragging) is to make contained components shrink and
appear as a small, vertical line? If you resize my window, you'll see what
I mean.
public class TNSwapPanel extends JPanel {
GridBagLayout gridBagLayout3 = new GridBagLayout();
// Top Panel
JPanel topSwapPanel = new JPanel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
TNSwapToolPanel toolPanel = new TNSwapToolPanel(); // Just three buttons
in its own panel as one class.
...
// Bottom panel
JPanel bottomSwapPanel = new JPanel();
GridBagLayout gridBagLayout2 = new GridBagLayout();
...
public TNSwapPanel() { // standard constructor here
...}
private void jbInit() throws Exception {
this.setLayout(gridBagLayout3);
...
// Top Panel setup
topSwapPanel.setLayout(gridBagLayout1);
topSwapPanel.setMinimumSize(new Dimension(575, 55));
jLabel1.setText("Swap Group");
jLabel2.setText("DB");
jLabel3.setText("Login");
loginText.setText("jTextField1");
topSwapPanel.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new
Insets(10, 5, 10, 5), 0, 0));
topSwapPanel.add(swapCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 10), 0, 0));
topSwapPanel.add(jLabel2, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 5), 0, 0));
topSwapPanel.add(dbCombo, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 10), 0, 0));
topSwapPanel.add(jLabel3, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 5), 0, 0));
topSwapPanel.add(loginText, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 30), 0, 0));
topSwapPanel.add(toolPanel, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 5), 0, 0));
// this.add(topSwapPanel, null);
this.add(topSwapPanel, new GridBagConstraints(0, 0,
GridBagConstraints.REMAINDER,
1, 0.1, 0.01, GridBagConstraints.NORTHWEST,
GridBagConstraints.BOTH, new Insets(0, 10, 0, 10), 0, 0));
// Bottom Panel setup
bottomSwapPanel.setLayout(gridBagLayout2);
bottomSwapPanel.setMinimumSize(new Dimension(575, 55));
jLabel4.setText("Date");
dateField.setText("jTextField1");
jLabel5.setText("Status");
statusField.setText("jTextField1");
jLabel6.setText("Pending Type");
jLabel7.setText("TN");
areacodeField.setText("jTextField1");
jLabel8.setText("-");
tnField.setText("jTextField1");
addBtn.setText("Add");
removeBtn.setText("Remove");
bottomSwapPanel.add(jLabel4, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new
Insets(10, 5, 10, 5), 0, 0));
bottomSwapPanel.add(dateField, new GridBagConstraints(1, 0, 1, 1, 0.0,
0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 10), 15, 0));
bottomSwapPanel.add(jLabel5, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 5), 0, 0));
bottomSwapPanel.add(statusField, new GridBagConstraints(3, 0, 1, 1, 0.0,
0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 10), 0, 0));
bottomSwapPanel.add(jLabel6, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 5), 0, 0));
bottomSwapPanel.add(pendCombo, new GridBagConstraints(5, 0, 1, 1, 0.0,
0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 10), 0, 0));
bottomSwapPanel.add(jLabel7, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 5), 0, 0));
bottomSwapPanel.add(areacodeField, new GridBagConstraints(7, 0, 1, 1,
0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 2), -25, 0));
bottomSwapPanel.add(jLabel8, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 2), 0, 0));
bottomSwapPanel.add(tnField, new GridBagConstraints(9, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 10), 0, 0));
bottomSwapPanel.add(addBtn, new GridBagConstraints(10, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 10), 0, 0));
bottomSwapPanel.add(removeBtn, new GridBagConstraints(11, 0, 1, 1, 0.0,
0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(10, 0, 10, 5), 0, 0));
this.add(bottomSwapPanel, new GridBagConstraints(0, 1,
GridBagConstraints.REMAINDER,
GridBagConstraints.REMAINDER, 0.0, 0.9,
GridBagConstraints.CENTER,
GridBagConstraints.BOTH, new Insets(0, 10, 0, 10), 26, 0));
// topSwapPanel.setPreferredSize(new Dimension(730, 55));
// bottomSwapPanel.setPreferredSize(new Dimension(730, 55));
}
// Main method for some testing purposes only
public static void main(String [] args) {
TNSwapPanel panel = new TNSwapPanel();
JFrame frame = new JFrame();
// Closing method and implementation for the class
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setTitle("TN Swap");
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setSize(800,150); // I had to set the low Y value to get the
appearance looking how I wanted it.
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height -
frame.getSize().height) / 2);
frame.setVisible(true);
}
// static initializer for setting look & feel
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {}
} // end of main()
}
Technical Details
Message-ID:
<85foov$4bs6@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<85507g$rmg5@bornews.borland.com> <38761BBD.73B606DD@inprise.com> <855ku4$s2s10@bornews.borland.com> <387A698D.DA042C1F@bilbo.bio.purdue.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,ecbc9a69fd2dad64 X-Google-Attributes: gid111d45,public From: "Jeff Marendo" <marendoj@commos.com> Subject: Re: Help with GridBagLayout manager Date: 2000/01/11 Message-ID: <85foov$4bs6@bornews.borland.com> X-Deja-AN: 571255229 References: <85507g$rmg5@bornews.borland.com> <38761BBD.73B606DD@inprise.com> <855ku4$s2s10@bornews.borland.com> <387A698D.DA042C1F@bilbo.bio.purdue.edu> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Organization: CommTech Corporation X-MSMail-Priority: Normal Reply-To: "Jeff Marendo" <marendoj@commos.com> Newsgroups: borland.public.jbuilder.java.swing