File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes user -Interfarce -HELP!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "user -Interfarce -HELP!!!!" Watch "user -Interfarce -HELP!!!!" New topic

user -Interfarce -HELP!!!!

Naf Rash
Ranch Hand

Joined: Feb 19, 2004
Posts: 85
I have the following piece of code but unfortunately the graphical user interface doesn't behave as I would like it to. For instance, each instruction should be followed by the relevant textfield underneath ie,
But unfortunately this does not happen. Also when I enlarge the screen the layout changes. How can I ammend this code to make it the way I want it. I have tried all sort but can't seem to get round this!
private void connectionForm(){

//Container d = getContentPane();
JPanel all = new JPanel();

/* The following code provides a text box and asks for the URL of the database that needs to be
* connected to.*/
JPanel northPanel = new JPanel();
urllabel = new JLabel(" Enter the name of the database.");
url = new JTextField(15);


/* The following code provides a text box and asks for the User-ID to allow a connection to the
* database to be established. */
JPanel centrePanel = new JPanel();
uidlabel = new JLabel(" Enter the User-ID for the specified database."
+ "NB: If no User-ID exists enter 'null'.");
centrePanel.add(uidlabel, BorderLayout.NORTH);
uid = new JTextField(15);


/* The following code provides a text box and asks for the Password to allow a connection to the
* database to be established. */
JPanel southPanel = new JPanel();
passwordlabel = new JLabel(" Enter the Password for the specified" +
"database. NB: If no Password exists enter 'null'.");
southPanel.add(passwordlabel, BorderLayout.NORTH);
//all.add(southPanel, BorderLayout.CENTER);
password = new JPasswordField(15);
southPanel.add(password, BorderLayout.SOUTH);

all.add(southPanel, BorderLayout.SOUTH);

JPanel minePanel= new JPanel();
mine = new JButton("Mine!");
minePanel.add(mine, BorderLayout.SOUTH);
all.add(minePanel, BorderLayout.SOUTH);

ActionHandler handler = new ActionHandler();

setSize(600, 300);

Warren Dew
Ranch Hand

Joined: Mar 04, 2004
Posts: 1332
The default layout for a JPanel is FlowLayout. Constants like BorderLayout.NORTH are just ints, so the JPanel thinks you're specifying an ordering in the flow layout rather than a position in a border layout.
Try replacing "new JPanel()" with "new JPanel(new BorderLayout())" wherever it occurs in your code, so that your JPanels will have BorderLayouts instead of FlowLayouts.
I agree. Here's the link:
subject: user -Interfarce -HELP!!!!
jQuery in Action, 3rd edition