954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

No able to set the jpanel positions

Hi
I am not able to set the position of Jpanel, having a tough time.

Code is attached.
1. How can I reduce the gap between
To and textbox
Cc and textbox
etc
2. How can I reduce the vertical space between Send/Contact/Spell/.... and the row containing To with textbox
I read tutorial like
http://www.leepoint.net/notes-java/GUI/layouts/30gridlayout.html
but no avail
Someone please help me
Thanks

Attachments EmailWindow2.java (10.26KB)
javafan
Newbie Poster
10 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

the JVM determines component spacing and sizing at runtime. It's pretty much out of your hands.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

You mean to say I have no control over the display
Then how do I do this?

javafan
Newbie Poster
10 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 
You mean to say I have no control over the display Then how do I do this?

Jwenting just said "It's pretty much out of your hands."
:confused:


I don't see what the problem is, how it looks is just pointless fluff. If it works it works. What more do you want.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

you have absolute control over the way the components are displayed in relation to each other.
You have very little control over how (what size and visual style) they're displayed at.

This is deliberate to enable the JVM to make it look decent on different operating systems that have different ways of doing things.
If you go and set that an input control is X pixels by Y pixels with a border of Z pixels that may look great on your Windows machine but completely crappy on a Mac or X terminal.
It may even be impossible to render there at all at that size.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Greetings:
You could try with GridBagLayout, it allows you to control a little more the appereance by using weights for the spaces that the components use, something like this:

GridBagLayout gridbag = new GridBagLayout();
this.getContentPane().setLayout(gridbag);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
//to add components you just asign a grid position and a weight
g.gridx=0;c.gridy=0;c.weightx=2;c.weighty=0;this.getContentPane().add(component,c);

Here is the description of GridbagLayout from java.sun, http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html

ROGENATOR
Newbie Poster
17 posts since Sep 2005
Reputation Points: 11
Solved Threads: 0
 

You could always set the layout to null and set the bounds, but I don't know if that's a good idea or not...... That is, if you are talking about positioning components.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

NullLayout is never recommended except on platforms where there is no other layout manager available (maybe some mobile platforms).

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You