Jer*_*225 1 java user-interface swing title joptionpane
在Java中使用JOptionPane时,如何在消息对话框中创建自定义标题?我目前有:
JOptionPane.showMessageDialog(null, "You won the game in " + tries + " tries!");
Run Code Online (Sandbox Code Playgroud)
我试图添加另一个参数,它给了我一个错误.有任何想法吗?
use*_*366 13
试试这个
JOptionPane.showMessageDialog(null, "You won the game in 7 tries!", "my title", JOptionPane.INFORMATION_MESSAGE);
Run Code Online (Sandbox Code Playgroud)
您需要提供消息类型(第4个参数),以便了解要显示的默认图标.
这是带有标题的对话框的正确语法:
JOptionPane.showMessageDialog(null, "This is the message", "This is the title", JOptionPane.INFORMATION_MESSAGE);
// Component; Text to appear in window; Title; This is the type of dialog (can be error, as well)
Run Code Online (Sandbox Code Playgroud)
注意,有四个参数,而不是三个(@Sanjay解释说,没有一个带有三个参数的方法)