1

Textarea と Button を含むカスタム SwingUtilities.InvokeandWait イベントを作成しようとしているため、ユーザーがデータを Textarea に貼り付けてボタンをクリックすると、それまでは制御は下がらないはずですが、正しく動作させることはできませんでした。

ダイアログメッセージを使用するのが最善の方法であることがわかったので、現在、InputDialogBoxに単一行のテキストフィールドではなく、より大きなTextAreaを追加しようとしています。また、カスタム ダイアログ ボックスを作成しようとしましたが、InvokeandWait はダイアログ ボックスをトリガーし、不要な次の行に移動します。

専門家の助けが必要です

  1. inputdialog(または)で単一行のテキストフィールドの代わりにTextareaを追加する方法
  2. [OK]ボタンを押すまでカスタムダイアログを処理する方法と、制御がプログラムの次の行に移動します。
4

2 に答える 2

3

カスタム ダイアログを作成する簡単な例 -

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);
    }
于 2011-06-14T08:38:51.103 に答える
2

JDialog は JFrame に似ています。必要に応じて任意のコンポーネントを追加できます。

また、invokeAndWait() も使用しません。ダイアログをモーダルにするだけで、思いどおりに動作します。

于 2011-06-13T01:45:48.600 に答える