I am trying to write an custom SwingUtilities.InvokeandWait 开发者_高级运维event , containing Textarea and Button ,so the once the user paste the data into Textarea and click button . Till then control should not go down ,but couldn't make it work correctly.
I figured out the best way would be using an dialog message, so now I am trying add a bigger TextArea instead of single line textfield in the InputDialogBox. I also tried to create a custome Dialog box but the InvokeandWait even just triggers the dialog box and goes to next lines which I don't want.
I need help from experts
- way to add a Textarea instead of single line textfield in inputdialog (or)
- way to handle the custom dialog till I press ok button in it and then control goes to next line of the program.
One simple example to create a Custom Dialog -
public class CustomDiaglogBox extends JFrame
{
// Variables declaration
private JLabel jLabel_Item;
private JLabel jLabel_Value;
public static JButton jButton_Add;
private JPanel contentPane;
public static JComboBox combo_item;
public static JComboBox combo_value;
public static JTextField text_Value;
public static JTextArea textArea_desc;
// End of variables declaration
public CustomDiaglogBox()
{
super();
create();
this.setVisible(true);
}
private void create()
{
jLabel_Item = new JLabel();
jLabel_Value = new JLabel();
jLabel_Description = new JLabel();
combo_value = new JComboBox();
text_Value = new JTextField();
textArea_desc = new JTextArea(20,20);
combo_item = new JComboBox(new String[]{""});
combo_item.setSelectedIndex(-1);
jButton_Add = new JButton();
contentPane = (JPanel)this.getContentPane();
//
// jLabel1
//
jLabel_Item.setHorizontalAlignment(SwingConstants.LEFT);
//jLabel_Item.setForeground(new Color(0, 0, 255));
jLabel_Item.setText("Item");
//
// jLabel2
//
jLabel_Value.setHorizontalAlignment(SwingConstants.LEFT);
// jLabel_Value.setForeground(new Color(0, 0, 255));
jLabel_Value.setText("Value");
// jButton1
//
jButton_Add.setBackground(new Color(204, 204, 204));
jButton_Add.setForeground(new Color(0, 0, 255));
jButton_Add.setText("Add");
jButton_Add.setEnabled(false);
jButton_Add.addActionListener(new AddTagWidnowListener()); //
// contentPane
//
contentPane.setLayout(null);
contentPane.setBorder(BorderFactory.createEtchedBorder());
contentPane.setBackground(Color.WHITE);
addComponent(contentPane, jLabel_Item, 5,10,106,18);
addComponent(contentPane, jLabel_Value, 5,47,97,18);
addComponent(contentPane, new JLabel("Description"), 5,87,97,18);
addComponent(contentPane, combo_item, 110,10,183,22);
addComponent(contentPane, combo_value, 110,45,183,22);
addComponent(contentPane, new JScrollPane(textArea_desc), 110,75,183,62);
addComponent(contentPane, jButton_Add, 150,145,83,28);
this.setTitle("MY CUSTOM DIALOG");
this.setLocation(new Point(276, 182));
this.setSize(new Dimension(335, 221));
this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
this.setResizable(false);
}
A JDialog is just like a JFrame. You can add any component to it that your want.
Also, you don't use invokeAndWait(). Just make the dialog modal and it will work the way you want.
精彩评论