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.