We help IT Professionals succeed at work.

simple GUI questions

MdFool
MdFool asked
on
390 Views
Last Modified: 2010-03-31
1. heres my code.all the variables that end in a L are labels and T are textfields.  I want the scrollpane to be in the center, which it is, but i want to it to take up the whole center, its only a small box now. what do i do?

2. the textfields are all lined up on the right but i want them all to be as far left as possible(ie lined up with the left side of the line_start area.

3. how do i size the components if i want a max or min size. i used setBounds and setSize but neither work....

JPanel p1 = new JPanel(new BorderLayout(10,10));
JPanel p = new JPanel(new GridLayout(0,1));
JPanel p2 = new JPanel();
JPanel p3 = new JPanel(new GridLayout(0,1));
 p.add(portL);
 p.add(portL);
 p.add(portT);
 p.add(serverL);    
 p.add(serverT);
 p.add(usernameL);
 p.add(usernameT);
p.add(passwordL);
 p.add(passwordT);
p.add(directoryL);
  p.add(directoryT);
     p.add(connectB);
     p.add(disConnectB);
     p3.add(fileServerScrollerT);
     p3.add(getFilesB);
     getFilesB.setEnabled(false);
     disConnect.setEnabled(false);
p1.add(p, BorderLayout.LINE_START);
p1.add(scrollPane, BorderLayout.CENTER);
p1.add(p3,BorderLayout.LINE_END);
 getContentPane().add(p1);
Comment
Watch Question

zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
1. p1.setLayout(new BorderLayout());

2. use GridbagLayout (instead of GridLayout) and anchor them to the west

3. setMinimumSize(), setMaximumSize(), setPreferredSize()
    Some or all of them will be taken into account depending of the LayoutManager

Commented:
Friend;

I'm not sure about your question but here are my share :

You can use several layout managers all together at the same time like, BorderLayout, GridLayout and
FlowLayout, this are the layouts that I always use.

For question no # 1 :
You can use GridLayout.CENTER

For question no # 2 :
You can use GridLayout.WEST Or FlowLayout.LEFT

For question no # 3 :
It was said above by zzynx :
setMinimumSize(), setMaximumSize(), setPreferredSize().

But anyways take this review links to ensure a good layout management.

Using Layout Managers
http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

Effective Layout Management: Short Course
http://java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/shortcourse.html

Layout Management
http://java.sun.com/docs/books/tutorial/uiswing/overview/layout.html

Hope it helps . . .
Javatm

Commented:
2. use new FlowLayout(FlowLayout.LEFT)

1 and 3 same as zzynx
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
sorry about the code, i sort of cut and pasted to get the point across because i didnt want to paste alot of code. ok for the code jimmack gave how do i make the labels on the west side to be aligned to the left instead of the right. and the getFilesB button is huge, is there any way to make it smaller?

Commented:
On my system, the labels are aligned to the left.

Enclose the getFilesB button inside a JPanel with a FlowLayout and it will then use it's default size.

        JPanel eastPanel = new JPanel();
        eastPanel.add(getFilesB);
        p3.add(eastPanel);
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.