Solved

New to Java; GUI?s

Posted on 2001-06-13
6
296 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
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
arguments to jar 5 33
Configure a Bean in an XML file 4 42
ejb stateless example 2 20
jboss 7.1 start up error 1 31
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

840 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