Solved

New to Java; GUI?s

Posted on 2001-06-13
6
302 Views
Last Modified: 2008-03-06
I'm new to Java and have a couple questions and RFC regarding laying out components.  I'm currently using JBuilder 3.5.  

My questions:

1)  What is the preferred method (or approach) for laying out components in a JFrame assuming one has a complex layout?  For clarity I'll offer a simple example:  

Suppose I want to construct a layout with four components: two JLables  and two JTextAreas.  Each JLable is to be followed by a JTextArea on its own line and centered similar to the following:
            JLable1  JtextArea1
            JLable2  JtextArea2

Hand coding this I could get something remotely similar to this by creating a content pane with a 2X1 GridLayout, insert two JPanels and add JLable1/JtextArea1 to JPanel1 and add JLable2/JtextArea2 to JPanel2. However the line spacing is going to change if the user sizes the JFrame.  Not ideal.  

2) JBuilder doesn't facilitate (in design mode) creating a content pane and putting two pannels inside it.  Rather it always creates the first panel then puts all subsequent panels inside the first.  I'm wondering if there is a reason for this?

RFC:
It doesn't seem to me that Swing has any easy method to layout  components having positional & aspect integrity that is independent of scale.  It seems what is needed is a vector based approach similar to that which Macromedia flash uses.

Finally I'm interested in finding someone who knows JBuilder to tutor me remotely via real time web meeting/desktop sharing.  Please add comment if interested.
0
Comment
Question by:Taurus
[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
6 Comments
 
LVL 2

Expert Comment

by:Nevyn
ID: 6188980
Use 2 GridLayouts(0, 1) and a BorderLayout.
Place the 2 JLabels into one GridLayout and the 2 JTextFields into the other.
Add the labels layout to the BorderLayout in the West position and the text fields layout to the Center position.
To keep the fields at reasonable heights, add the BorderLayout to another BorderLayout in the North position.

JPanel base = new JPanel( new BorderLayout() );
JPanel p = new JPanel( new GridLayout(0, 1) );
p.add( label1 );
p.add( label2 );
base.add(p, "West");
p = new JPanel( new GridLayout(0, 1) );
p.add( field1 );
p.add( field2 );
base.add(p, "Center");
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 6189595
0
 

Expert Comment

by:balugaa
ID: 6192919
with JBuilder you have the option of using an free layout
similar to the one on VC++

The thing is you set the Layout to null

ie. getContentPane().setLayout(null);

It is one of the options in design view set Layout to null
and you can freely place your controls where ever you like

alternatively you can use setBounds(x,y,w,h) and place the components i.e

lbl.setBounds(0,0,10,10);

getContentPane().add(lbl, null);

If you are using JBuilder change the layout to null and off you go
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
Vernstump earned 75 total points
ID: 6216927
You have to be careful when using the NULL for the layout.

Running your APP on diffrent OS might cause painting issues.

If you are not concerned with using JBuilders Libraries then you can use what is supported by JBuilder.

It is a layout called XY Layout. It sets up everything according to there relative position from the upper left corner of the component.

This always seems to work the best!!


Good luck
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6703348
Taurus,

PLEASE UPDATE AND FINALIZE all your open questions.  I will be adding this comment to them so that you will receive Email notification of them all.

If more is needed, please advise the experts; if you need my help to split points or take some other action, just comment and I'll return as soon as I can.

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6705682
Thank you for returning and updating/finalizing your questions, it is appreciated.  I'd like to ask if you've assigned "B" grades because of the quality of the information or just because that is the default setting?  I've been asking our Engineering department to consider adjusting this.  If you feel any of the "B" grades you've given were actually "A" level responses, just comment and I'll correct it.

The WHAT'S NEW link on the left has been updated to reflect some of the transitions we're undergoing, and will be updated again shortly, so highly recommend checking that for updates.

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

688 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