Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2006

Tip: Looking for answers? Try searching our database.

FlowLayout problem

Thread view: 
fb - 05 Feb 2006 06:22 GMT
Hello everyone.  I'm having a small bit of trouble controlling the
location of my textfield using a flowlayout manager.  As it stands, the
textfield sits next to the label.  I was wondering if there is a way to
center the textfield 2 lines down from the label (~24 pixels I suppose).
Example code is below (It even compiles this time.  :-) )

On a side question, is it possible to place the components wherever I
wish, without turning off the Layout manager?

ttyl.

/* store in file MyCard.java */

import java.applet.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.geom.*;

public class MyCard extends Applet {

    //Main applet is BorderLayout
    BorderLayout mainBorderLayout = new BorderLayout();

    //Make a card layout
    CardLayout stockCardLayout = new CardLayout();

    //Panel for holding the cards
    Panel stockPanel = new Panel();

    public void init() {
        this.setSize(300,500);

        //Set the layout of the Panel to CardLayout
        stockPanel.setLayout(stockCardLayout);
        //Place it in the Center of the Applet - BorderLayout
        this.add(stockPanel, BorderLayout.CENTER);

        Panel theIBMPanel = new Panel();

        stockPanel.add(theIBMPanel, "IBMCard");

        //Add a title to the IBM Card
        Label myIBMTitle = new Label("IBM Stock Information");
        theIBMPanel.add(myIBMTitle);

        //Add a textfield to enter a stock name
        TextField myIBMTextField = new TextField(30);
        theIBMPanel.add(myIBMTextField);

        this.setVisible(true);
    }
}
HGA03630@nifty.ne.jp - 05 Feb 2006 09:01 GMT
FlowLayout just flows. You can't do fine
control on layout using it.
Use GridBagLayout or Box/BoxLayout.
Using multiple nested sub-containers are
key to the successfull layout design.
Paulus de Boska - 05 Feb 2006 12:12 GMT
> On a side question, is it possible to place the components wherever I
> wish, without turning off the Layout manager?
Well, you can position components where you want them with setBounds,
but then the layout manager has to be turned of, which brings a lot of
disadvantages, so a better approach is, to use a layout manager for a
main panel division and look to the individual panels to see if there
are layout managers that can do what you want or possibly divide panels
further up into 'sub'-panels, each with their own lm's.
Here's an example that shows a main division and the use of a gridbaglm

http://javalessons.com/cgi-bin/ui/java-swing.cgi?1cd=gbl&sid=ao789

You can find other lm-examples in the GUI/Swing unit.

---
Paul Hamaker, SEMM
http://javalessons.com
Roedy Green - 05 Feb 2006 12:33 GMT
> I'm having a small bit of trouble controlling the
>location of my textfield using a flowlayout manager

Flowlayout is a very rough and ready layout. See
http://mindprod.com/jgloss/layout.html for one of the ones that give
you finer control.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

fb - 06 Feb 2006 02:49 GMT
>>I'm having a small bit of trouble controlling the
>>location of my textfield using a flowlayout manager
>
> Flowlayout is a very rough and ready layout. See
You can say that again...
> http://mindprod.com/jgloss/layout.html for one of the ones that give
> you finer control.

Thanks for the link!
Roedy Green - 05 Feb 2006 12:35 GMT
>On a side question, is it possible to place the components wherever I
>wish, without turning off the Layout manager?

You can. Set the layout manage to null, and set the location and size
of each component. This is considered very wicked.

What you should do instead is write your own layout manager so you at
least separate the logic for determining position from everything
else.

I show you a simple example StarLayout at
http://mindprod.com/jgloss/layout.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

fb - 06 Feb 2006 02:51 GMT
>>On a side question, is it possible to place the components wherever I
>>wish, without turning off the Layout manager?
>
> You can. Set the layout manage to null, and set the location and size
> of each component. This is considered very wicked.

Ok...I will try my best to avoid it...  :)

> What you should do instead is write your own layout manager so you at
> least separate the logic for determining position from everything
> else.
Ok, I'll give it a shot.

> I show you a simple example StarLayout at
> http://mindprod.com/jgloss/layout.html

Merci.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.