Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to add a label and text field to a JFrame?

0 views
Skip to first unread message

Guang Mei

unread,
Oct 19, 2001, 5:58:18 PM10/19/01
to
Hi:

I just downloaded Forte (Community Edition v3.0) from Sun to start learing
java. I created a simple new program which creates a JFrame. I want to add a
couple of "label" and "textfield" to the frame (or form?) and I am having
hard time to do that. It sesms

Forty do not allow you to visually add componet after JFrame is selected
visually.

Here is the snip:

------------

public class OpticsReflection extends javax.swing.JFrame {

/** Creates new form opticsreflect */

public OpticsReflection() {

initComponents();

initMoreComponents();

setBounds( 100, 100, 400, 400 );


private void initComponents() {

snip....


getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());


snip....

pack();

}

private void initMoreComponents() {

iAngleLabel = new javax.swing.JLabel ();

iAngleLabel.setText ("Incident Angle:");

iAngleLabel.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);

iAngleLabel.setHorizontalTextPosition(javax.swing.JLabel.CENTER);


getContentPane().add(iAngleLabel); // <--- this line generated error when
executing the program

}

}

-------

My code seems to compile (no error message), but when I execute, I got:


Error message:

java.lang.IllegalArgumentException

at
org.netbeans.lib.awtextra.AbsoluteLayout.addLayoutComponent(AbsoluteLayout.j
ava:128)

at java.awt.Container.addImpl(Container.java:380)

at java.awt.Container.add(Container.java:267)

at
opticsreflection.OpticsReflection.initMoreComponents(OpticsReflection.java:1
12)

at opticsreflection.OpticsReflection.<init>(OpticsReflection.java:21)

at opticsreflection.OpticsReflection.main(OpticsReflection.java:90)

Question:

1. Does anyone know how to add a label or textfiled (component) to a JFrame
(or layout?) in Forte visually ?

2. If I have to add a label by writing my own code, say in method
"initMoreComponents", what command should I use? could some one give me a
example?

Thanks.

Arnaud Berger

unread,
Oct 22, 2001, 10:13:34 AM10/22/01
to
IMO, you should start with less-exotical layouts.
See the available layouts from java.awt , and start with the simpler ones
(FlowLayout, BorderLayout).

Arnaud


"Guang Mei" <gm...@proteome.com> a écrit dans le message news:
Ii1A7.1057$oc.1...@news.shore.net...

0 new messages