• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

user -Interfarce -HELP!!!!

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();

}
 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic