wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "user -Interfarce -HELP!!!!" Watch "user -Interfarce -HELP!!!!" New topic
Author

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,
INSTRUCTION
TEXTFIELD
INSTRUCTION
TEXTFIELD
INSTRUCTION
TEXTFIELD
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.");
northPanel.add(urllabel,BorderLayout.NORTH);
//all.add(northPanel,BorderLayout.NORTH);
url = new JTextField(15);
northPanel.add(url,BorderLayout.SOUTH);

all.add(northPanel,BorderLayout.NORTH);


/* 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);
//all.add(centrePanel,BorderLayout.CENTER);
uid = new JTextField(15);
centrePanel.add(uid,BorderLayout.SOUTH);

all.add(centrePanel,BorderLayout.CENTER);


/* 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();
url.addActionListener(handler);
uid.addActionListener(handler);
password.addActionListener(handler);
mine.addActionListener(handler);


setContentPane(all);
validate();
setSize(600, 300);
show();

}
Warren Dew
blacksmith
Ranch Hand

Joined: Mar 04, 2004
Posts: 1332
    
    2
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: http://aspose.com/file-tools
 
subject: user -Interfarce -HELP!!!!
 
Similar Threads
Removing user-interface components- HELP!
What is wrong with my code?
[newbie] Syntax error on token(s), misplaced construct(s)
Removing a contentPane- HELP!
run-time error HELP!