The Artima Developer Community
Sponsored Link

Java Answers Forum
java.lang.illegalArgumentException....

1 reply on 1 page. Most recent reply: Jan 12, 2004 5:47 AM by Adam Duffy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Gianluca

Posts: 2
Nickname: gianluca
Registered: Jan, 2004

java.lang.illegalArgumentException.... Posted: Jan 12, 2004 4:17 AM
Reply to this message Reply
Advertisement
I wrote this code :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JAutoDialogo extends JFrame {
private JTextField t1;
private JTextField t2;
public static void main(String argv[]){
JAutoDialogo ist = new JAutoDialogo();
}//end main
JAutoDialogo(){
JPanel pannelloTesto = new JPanel(new GridLayout(0,2,3,3));
JPanel pannelloBottoni = new JPanel();
setTitle(getClass().getName());
pannelloTesto.add(new JLabel("Testo1"),JLabel.LEFT);
pannelloTesto.add(t1 = new JTextField(""));
pannelloTesto.add(new JLabel("Testo2"),JLabel.LEFT);
pannelloTesto.add(t2 = new JTextField(""));
pannelloBottoni.setLayout(new FlowLayout());
((JButton) pannelloBottoni.add(new JButton ("Scambia")))
.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String scambio = t1.getText();
t1.setText(t2.getText());
t2.setText(scambio);
}//end actionPerformed
});
((JButton) pannelloBottoni.add(new JButton ("Esci")))
.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}//end actionPerformed
});
getContentPane().add(pannelloTesto,"Center");
getContentPane().add(pannelloBottoni,"South");
pack();
setVisible(true);
}//end costruttore AutoDiaologo
}//end class JAutoDialogo

I'm working in the directory c:\lavoro, when I do:

c:\lavoro> java JAutoDialogo

I have this error :

Exception in thread "main" java.lang illegalArgumentException: illegal component position
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at jAutoDialogo.<init>(JautoDialogo.java:15)
at jAutoDialogo.main(JautoDialogo.java:9)


Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: java.lang.illegalArgumentException.... Posted: Jan 12, 2004 5:47 AM
Reply to this message Reply
Instead of the lines

pannelloTesto.add(new JLabel("Testo1"),JLabelLEFT);
pannelloTesto.add(t1 = new JTextField(""));
pannelloTesto.add(new JLabel("Testo2"),JLabel.LEFT);


try

pannelloTesto.add(new JLabel("Testo1"));
pannelloTesto.add(t1 = new JTextField(""));
pannelloTesto.add(new JLabel("Testo2"));


Adam

Flat View: This topic has 1 reply on 1 page
Topic: delay embedding Previous Topic   Next Topic Topic: String manipulations

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use