![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
simple GUI assistance
Hello. I have 2 questions about why my GUI seems to be acting up.
1) I have a few buttons that I'm adding to the south of a BorderLayout. When I run the program only the last button I add shows and it consumes the entire south portion. How could I center all the buttons in the south portion so that A) each button is the size equal to the amount of text representing the button and B) are centered in the southern panel so that all 3 buttons together do not consume the entire southern panel. //this code comes from inside the constructor of my class that extends JFrame
add(jbtQuit, BorderLayout.SOUTH);
add(jbtNew, BorderLayout.SOUTH);
add(jbtSubmit, BorderLayout.SOUTH);2) In the center of the aforementioned class I have a panel. The panel is designated as a separate class extending JPanel. I set this panel's layout to a grid layout, 8x2, for 8 labels and text fields. Anyways, the grid layout is not making sense, or not doing what the book I'm referencing seems to explain. Seeing that this grid layout has 2 columns, I'll refer to each as column 1 for the left or 2 for the right column. Column 1 is all labels, designating their respective text fields in column 2. What is happening is this. The labels in column 1 seem to be "left" justified, and the text fields of column 2 are "center" or "right justified (right if I stretch the frame to a wider size). I would like so that the labels of column 1 are a few pixels away from their respective text fields, rather then basically the width of the frame. It doesn't look very cool to me to have this gigantic space between these types of components. The constructor for the border layout has hor. and vert. gap but they don't seem to do anything? This is the class I'm adding to the BorderLayout center of another class. It's nothing special, but it's causing me a headache : ) public class Customer extends JPanel{
JLabel jlblCustId = new JLabel("Customer ID");
JLabel jlblFirst = new JLabel("First Name");
JLabel jlblLast = new JLabel("Last Name");
JLabel jlblCity = new JLabel("City");
JLabel jlblZip = new JLabel("Zip Code");
JTextField jtfCustId = new JTextField(8);
JTextField jtfFirst = new JTextField(8);
JTextField jtfLast = new JTextField(8);
JTextField jtfCity = new JTextField(8);
JTextField jtfZip = new JTextField(8);
Customer()
{
setLayout(new GridLayout(8,2)); //had hgap and vgap in there but did nothing
add(jlblCustId);
add(jtfCustId);
add(jlblFirst);
add(jtfFirst);
add(jlblLast);
add(jtfLast);
add(jlblCity);
add(jtfCity);
add(jlblZip);
add(jtfZip);
}
}Thanks a ton. -Zack |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Re: simple GUI assistance
1) a,b) Add the buttons to a JPanel with a FlowLayout layout manager, and add the panel to the SOUTH region of a window with a BorderLayout layout manager.
2) You will have to use a GridBayLayout, a more powerful (and more difficult to use) layout manager similar to GridLayout. You can adjust the specific layout details of each component added to the former via a GridBagConstraints object. Last edited by titaniumdecoy; Apr 9th, 2008 at 12:24 AM. |
|
|
|
|
|
#3 | |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
Re: simple GUI assistance
Quote:
For the 2nd question I figured out a different way to get the effect I was looking for. Thanks a lot for the help. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dos based Gui | Damienallen | C | 12 | Oct 1st, 2007 11:09 AM |
| Which is easier for making a GUI program? | 357mag | Java | 6 | Jul 29th, 2007 6:08 PM |
| Programming a simple GUI | bulio | Other Scripting Languages | 12 | Jun 9th, 2007 3:29 PM |
| a simple linking loader for SIC/XE | programmingnoob | C++ | 3 | Feb 27th, 2006 12:35 AM |
| Simple Function Questions | meverha1 | C++ | 16 | Sep 12th, 2005 2:25 AM |