Solved

New to Java; GUI?s

Posted on 2001-06-13
6
294 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Jpanels and Jframe 8 33
Basic Java Case or If-Else statement... 3 50
login form jsp example 2 25
How to determine if a string is a valid SHA value 7 32
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
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.

770 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