本文介绍了JOptionPane每行有多个按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在每行上显示带有多个JButtonsJOptionPane.showinputDialog()?我不是在谈论YesNoCancel按钮,而是在JOptionPane.showinputDialog内容区域中显示的多个自定义标签JButtons?

How would I go about displaying a JOptionPane.showinputDialog() with multiple JButtons on each line? I am not talking about the Yes, No, Cancel buttons but multiple custom labeled JButtons that displays in the content area of JOptionPane.showinputDialog?

所以我也需要从JOptionPane获取按下按钮的值.

so I would need to get the value of the button pressed from the JOptionPane as well.

推荐答案

您可以将任何JComponents放在 JOptionPane ,我看不到任何限制,JOptionPane是相同的顶级容器JFrameJDialogJWindow,但与普通的Top-Level Containers相反,JOptionPane实现了来自内置功能Integer的值,也意味着按钮YESNOOKCANCELCLOSE

You can place any JComponents to the JOptionPane, there I can't see any limits, JOptionPane is same Top-Level Container as JFrame, JDialog or JWindow, but in contrast with plain Top-Level Containers, JOptionPane has implemented return events from built-in funcionalities in Integer value, meaning buttons YES, NO, OK, CANCEL and CLOSE too,

将所有JButton放入数组

put all JButtons to the Array

String[] buttons = { "Yes", "Yes to all", "No", "Cancel".... };
int returnValue = JOptionPane.showOptionDialog(null, "Narrative", "Narrative",
        JOptionPane.WARNING_MESSAGE, 0, null, buttons, buttons[i]);
System.out.println(returnValue);

这篇关于JOptionPane每行有多个按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:07
查看更多