gpt4 book ai didi

java - 如何在单击 JButton 后添加显示 "OK"和 "Cancel"的面板?

转载 作者:行者123 更新时间:2023-12-01 13:19:25 25 4
gpt4 key购买 nike

所以基本上我有这个按钮。 (右键)

我想要它,所以当您单击此按钮时,会出现一个通知/弹出窗口,显示“恭喜,您单击了一个按钮。”然后只需说“确定”和“取消”(两者都只是退出面板,实际上是相同的“任务”)

我使用了 JOptionPane,但这当然行不通,因为它有一个我不想要的大文本栏。

所以我猜您必须制作一个 JPanel 并在该面板内添加 JButtons“确定”和“取消”?我被难住了。

rightbutton = new JButton("Right.");
add(rightbutton);
rightbutton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
//what do we want to happen when we
//click the button
JOptionPane.showInputDialog("Congratulations, you clicked the button.");

谢谢!

最佳答案

您可以通过向 JOptionPane 组件传递一些参数来自定义它。

public static int showOptionDialog(Component parentComponent,
Object message,
String title,
int optionType,
int messageType,
Icon icon,
Object[] options,
Object initialValue)
throws HeadlessException


optionType
Defines the set of option buttons that appear at the bottom of the dialog box:
DEFAULT_OPTION
YES_NO_OPTION
YES_NO_CANCEL_OPTION
OK_CANCEL_OPTION

OK_CANCEL_OPOTION 是您想要的吗?

关于java - 如何在单击 JButton 后添加显示 "OK"和 "Cancel"的面板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22162656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com