Every time I click on the More button, the TextField doesnt show up.
It like, the panel is not refreshed?
/****************************************************************/
/* Hello */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Summary description for Hello
*
*/
public class Hello extends JFrame
{
// Variables declaration
private JScrollPane jScrollPane1;
private JButton More;
private JPanel contentPane;
//-----
private JTextField ValueTextField;
private JComboBox LabelComboBox;
private JComboBox ValueComboBox;
private JPanel jPanel1;
private int ypos = 30;
private String[] str1 = {"1", "2", "3"};
private String[] str2 = {"a", "b", "c"};
//-----
// End of variables declaration
public Hello()
{
super();
initializeComponent();
this.setVisible(true);
}
private void initializeComponent()
{
jScrollPane1 = new JScrollPane();
More = new JButton();
contentPane = (JPanel)this.getContentPane();
//-----
ValueTextField = new JTextField();
LabelComboBox = new JComboBox(str1);
ValueComboBox = new JComboBox(str2);
jPanel1 = new JPanel();
//-----
//
// jScrollPane1
//
jScrollPane1.setViewportView(jPanel1);
//
// More
//
More.setText("More");
More.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
More_actionPerformed(e);
}
});
//
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jScrollPane1, 69,21,441,198);
addComponent(contentPane, More, 210,228,83,28);
//
// ValueTextField
//
ValueTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
ValueTextField_actionPerformed(e);
}
});
//
// LabelComboBox
LabelComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
LabelComboBox_actionPerformed(e);
}
});
//
// ValueComboBox
ValueComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
ValueComboBox_actionPerformed(e);
}
});
//
// jPanel1
//
jPanel1.setLayout(null);
jPanel1.setPreferredSize(new Dimension(422, 600));
addComponent(jPanel1, ValueTextField, 288,ypos,100,22);
addComponent(jPanel1, LabelComboBox, 24,ypos,100,22);
addComponent(jPanel1, ValueComboBox, 155,ypos,100,22);
this.setTitle("Hello - extends JFrame");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(646, 430));
}
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
private void More_actionPerformed(ActionEvent e)
{
System.out.println("\nMore_actionPerformed(ActionEvent e) called.");
ypos = ypos + 30;
ValueTextField.revalidate();
LabelComboBox.revalidate();
ValueComboBox.revalidate();
LabelComboBox.setEnabled(false);
ValueTextField = new JTextField();
LabelComboBox = new JComboBox(str1);
ValueComboBox = new JComboBox(str2);
ValueTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
ValueTextField_actionPerformed(e);
}
});
LabelComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
LabelComboBox_actionPerformed(e);
}
});
ValueComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
ValueComboBox_actionPerformed(e);
}
});
addComponent(jPanel1, ValueTextField, 288,ypos,100,22);
addComponent(jPanel1, LabelComboBox, 24,ypos,100,22);
addComponent(jPanel1, ValueComboBox, 155,ypos,100,22);
jPanel1.revalidate();
}
private void ValueTextField_actionPerformed(ActionEvent e)
{
System.out.println("\nValueTextField_actionPerformed(ActionEvent e) called.");
}
private void LabelComboBox_actionPerformed(ActionEvent e)
{
System.out.println("\nLabelComboBox_actionPerformed(ActionEvent e) called.");
Object o = LabelComboBox.getSelectedItem();
System.out.println(">>" + ((o==null)? "null" : o.toString()) + " is selected.");
}
private void ValueComboBox_actionPerformed(ActionEvent e)
{
System.out.println("\nValueComboBox_actionPerformed(ActionEvent e) called.");
Object o = ValueComboBox.getSelectedItem();
System.out.println(">>" + ((o==null)? "null" : o.toString()) + " is selected.");
}
//============================= Testing ================================//
//= =//
//= The following main method is just for testing this class you built.=//
//= After testing,you may simply delete it. =//
//======================================================================//
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new Hello();
}
//= End of Testing =
}
Message was edited by:
Shaodw_boi