?
Solved

Please help me with layout

Posted on 1998-06-21
9
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 4

Accepted Solution

by:
evijay earned 200 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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
 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

752 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