[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Please help me with layout

Posted on 1998-06-21
9
Medium Priority
?
224 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
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.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 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