自定义对话框 java swing

发布于 2024-11-15 03:28:17 字数 369 浏览 1 评论 0原文

我正在尝试编写一个自定义 SwingUtilities.InvokeandWait 事件,包含 Textarea 和 Button ,因此一旦用户将数据粘贴到 Textarea 中并单击按钮。到那时控制不应下降,但无法使其正常工作。

我发现最好的方法是使用对话框消息,所以现在我尝试在 InputDialogBox 中添加更大的 TextArea 而不是单行文本字段。 我还尝试创建一个自定义对话框,但 InvokeandWait 甚至只是触发该对话框并转到我不想要的下一行。

我需要专家的帮助

  1. 来添加文本区域而不是输入对话框中的单行文本字段 (或)
  2. 处理自定义对话框的方法,直到我按其中的“确定”按钮,然后控制转到程序的下一行。

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

  1. way to add a Textarea instead of single line textfield in inputdialog
    (or)
  2. way to handle the custom dialog till I press ok button in it and then control goes to next line of the program.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妄想挽回 2024-11-22 03:28:18

JDialog 就像 JFrame 一样。您可以添加任何您想要的组件。

另外,您不使用 invokeAndWait()。只需将对话框设置为模态,它就会按照您想要的方式工作。

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.

墨落成白 2024-11-22 03:28:17

创建自定义对话框的一个简单示例 -

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);
    }

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);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文