borderlayout

hi

i am creating a JPanel which is on a jaframe with 3 JTextFields and 3 JLabels

i also have a menu system at the top of the page

i have decided to use BorderLayout to arrange the items on the JPanel.

Menu is set to NORTH

what i'm having trouble with is geting it to look like this

-

MENU SYSTEM

JLabel1JTextField1}this is the JPanel design i want

JLabel2JTextField2

JLabel3JTextField3

--

is there another way around this by using a different layout manager or can i achieve what i want from this layout manager

thanks

Jon

[616 byte] By [southamptona] at [2007-11-27 0:45:06]
# 1

Read the [url http://java.sun.com/docs/books/tutorial/uiswing/TOC.html]Swing Tutorial[/url]

There is a section on "How to Use Menus" (you don't add the menu to the NORTH of a BorderLayout.

There is also a section on "How to Use Spring Layout"

The main point about layout managers it that you don't need to use one for the entire frame. You can create sub panels that each use different layout managers.

camickra at 2007-7-11 23:09:55 > top of Java-index,Desktop,Core GUI APIs...
# 2

i have gone through the tutorial and have made my code compile but when i run it nothing seems to happen

label1 = new JLabel("CategoryID");

panel.add(label1);

SpringLayout.Constraints labelCons = s.getConstraints(label1);

labelCons.setX(Spring.constant(5));

labelCons.setY(Spring.constant(5));

i have a jframe and a jpanel i am adding the labels and textfields onto the panel but they are not showing i think there is possibly a mistake with the last three lines of code but am unsure

i have created a new instance of springlayout and have applied this to the frame

any ideas where im going wrong?

southamptona at 2007-7-11 23:09:55 > top of Java-index,Desktop,Core GUI APIs...
# 3

ok forget the last post as i found another way of doing it which i am sure will be a better way but i cannot get one line to compile

String[] labels = {"CategoryID: ", "Name: ", "Category Type:"};

int numPairs = labels.length;

//Create and populate the panel.

JPanel p = new JPanel(new SpringLayout());

for (int i = 0; i < numPairs; i++) {

JLabel l = new JLabel(labels[i], JLabel.TRAILING);

p.add(l);

JTextField textField = new JTextField(10);

l.setLabelFor(textField);

p.add(textField);

}

//Lay out the panel.

SpringUtilities.makeCompactGrid(p, numPairs, 2, /*rows, cols*/ 6, 6,/*initX, initY*/ 6, 6);//xPad, yPad

the last line

springutilities.makecompactgrid(....)

wont compile

it says the varible SpringUtilities is not found

any help much welcomed

southamptona at 2007-7-11 23:09:55 > top of Java-index,Desktop,Core GUI APIs...
# 4
http://java.sun.com/docs/books/tutorial/uiswing/layout/examples/SpringUtilities.java
kirillga at 2007-7-11 23:09:55 > top of Java-index,Desktop,Core GUI APIs...
# 5

im still having problems with this one line i even copy and paste the code given in the example into a new class to see if it was a problem with there class and it is(well on my laptop anyway)

SpringUtilities.makeCompactGrid(p, numPairs, 2, /*rows, cols*/ 6, 6,/*initX, initY*/ 6, 6);//xPad, yPad

this is the line it does not like is SpringUtilities.makeCompactGrid(...)

it cant find variable SpringUtilities

i have looked in various scripts and cannot find anyone who has a variable called SpringUtilities

this is the only line i need fixed and any help would be much welcomed

Jon

southamptona at 2007-7-11 23:09:55 > top of Java-index,Desktop,Core GUI APIs...
# 6
Somoene's just give you the source code for SpringUtilities - you need to create that class, it's not part of the JDK.An alternative to consider when producing forms is TableLayout (Google for it) - it's very well suited to that task.
itchyscratchya at 2007-7-11 23:09:55 > top of Java-index,Desktop,Core GUI APIs...
# 7
If I were you I would do like this:Border layout on content pane, menu on north, Jpanel stuff at centerGrid layout on JPanel stuff, labels and fields insie stuff.
Icycoola at 2007-7-11 23:09:55 > top of Java-index,Desktop,Core GUI APIs...
# 8
GridLayout isn't suitable for laying out forms.
itchyscratchya at 2007-7-11 23:09:55 > top of Java-index,Desktop,Core GUI APIs...