Solved

Please help me with layout

Posted on 1998-06-21
9
174 Views
Last Modified: 2010-03-30
Hello!
I'm getting crazy over all those Layouts (FlowLayout, CardLayout, etc).
I don't know which one to use.

This is how my frame should look:
A single line label
A single line label
A multi line label

OK button

All that might change is the height of the third label.
I want the OK button to be a bit under it, no matter if the third label contains one row or six, and I want the frame to end just below the button...

Could you point me to the right layout to use?

I thought that FlowLayout would be the one, but it shrinks all the controls to their minimum size.

Thanks in advance, Martin
0
Comment
Question by:martinag
  • 5
  • 4
9 Comments
 
LVL 4

Accepted Solution

by:
evijay earned 50 total points
ID: 1223467
let us assume your labels be label1, label2, label3. Here is a piece of code useful for you

Label label1, label2, label3.

frame.setLayout(new BorderLayout());
Panel subPanel = new Panel();
subPanel.setLayout(new GridLayout(2, 1));
subPanel.add(label1);
subPanel.add(label2);
frame.add("North", subPanel);
frame.add("Center", label3);

This should give you the layout you want.

0
 
LVL 4

Author Comment

by:martinag
ID: 1223468
Almost...
I tried adding the OK button for myself, by adding a new line of code:
this.add("South", ok);
It adds the button to the south, but it adds it VERY southly. Also, its width is the same as the frame's.

If you could come up with another bright idea, it would be great.

Martin
0
 
LVL 4

Expert Comment

by:evijay
ID: 1223469
Please create a panel and add the button to that panel and add the panel to the button

Panel tmpPanel = new Panel();
tmpPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
tmpPanel.add(ok);  // add your ok button or any other buttons here

this.add("South", tmpPanel);

0
 
LVL 4

Expert Comment

by:evijay
ID: 1223470
Sorry for the typo, The first sentence should go like this

Please create a panel and add the button to that panel and add the panel to the frame

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Author Comment

by:martinag
ID: 1223471
All right, everything looks great, but the frame doesn't resize automatically.
I've tried this.setSize(this.getPreferredSize()); but the frame has got the smallest size ever possible.
Could you fix that?

Martin
0
 
LVL 4

Expert Comment

by:evijay
ID: 1223472
Just invoke

pack();

after adding all the components and before calling setVisible or show method.


0
 
LVL 4

Author Comment

by:martinag
ID: 1223473
Looks great!

With your multi-line label and all the help with this, you have definitely deserved to be mentioned at the "Thanks!" dialog (which I think I will manage to design now :-))!
0
 
LVL 4

Expert Comment

by:evijay
ID: 1223474
Please not that there can be a lot of enhancements possible to multiline label. As of now, it doesnt support label alignment within the component. It is easy to add that to the code.
0
 
LVL 4

Author Comment

by:martinag
ID: 1223475
Yes, I have noticed that it isn't perfect, but it is enough for me...

It will be a challenge to get it perfect. Some day...
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now