Solved

New to Java; GUI?s

Posted on 2001-06-13
6
292 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

758 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

21 Experts available now in Live!

Get 1:1 Help Now