我有这样的布局JOptionPane:
JCheckBox checkbox = new JCheckBox("Do not show this message again.");
String message = "Level loaded successfully";
Object[] params = {message, checkbox};
int n = JOptionPane.showConfirmDialog(p, params, "Draft saving",
JOptionPane.PLAIN_MESSAGE);
Run Code Online (Sandbox Code Playgroud)
一切都很好,除了...的显示Icon,
理想情况下,我不想有一个Icon(因此JOptionPane.PLAIN_MESSAGE),但我得到了一个default Icon.
我怎么能改变这个?
贾森
我有一个带有物体的arraylist和一个正在运行的Gui.我正在寻找一种方法来弹出一个小框架或框或类似于显示arraylist中的对象的方法.用户现在应该能够选择一个或多个随后返回的项目.
我已经有了optionpane,但我可以选择一个对象
Object[] possibilities = lr.declarationList.toArray();
String s = (String)JOptionPane.showInputDialog(
gui.getFrame(),
"Choose Target Nodes",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
null);
Run Code Online (Sandbox Code Playgroud)
也许一个弹出列表会有所帮助.
我有一个像这样的选项对话框:
String[] options = ["Yes", "No"]; //button names
int n = JOptionPane.showOptionDialog(singleFrameService.getFrame(),
"Some Question?",
"",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, //do not use a custom Icon
options, //the titles of buttons
options[0]); //default button title
//if press yes
if (n == JOptionPane.YES_OPTION){
//make some if pressed Yes
}
Run Code Online (Sandbox Code Playgroud)
当我使用鼠标并按是/否 - 一切正常...但是当我开始使用键盘时,按TAB转到"否"按钮,然后按ENTER键 - 工作"是"选项
我很好奇,我想知道是否有办法让JOptionPane的顶部变成不同的颜色,比如红色或橙色.另外我想知道如何更改JOptionPane左侧的图像.我猜这是不可能的,因为它已经是一个从java使用的方法.但我不是专家.
我很抱歉,如果这听起来像一个愚蠢的问题,但我在JOptionPane的自定义按钮上到处搜索.我遇到了如何实现特殊按钮,但我似乎无法在我的程序中使用它.
int choice;
Object[] doors = { "Door 1", "Door 2", "Door 3" };
JFrame frame = new JFrame();
input = "Which door do you choose?";
choice = JOptionPane.showOptionDialog(frame, input,
"Doors",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
doors,
doors[2]);
if (car == 1 && choice.equals(doors[0])) {
open = 3; option = 2;
}
if (car == 1 && choice.equals(doors[1])) {
open = 3; option = 1;
}
if (car == 1 && choice.equals(doors[2])) {
open = 2; option = 1;
}
if (car …Run Code Online (Sandbox Code Playgroud) 我想使用JOptionPane创建一个showOptionDialog,它有两个按钮:Metric和Imperial.如果说,单击"度量标准",将加载度量标准GUI.相反,如果单击Imperial,则会加载Imperial GUI.
我该怎么做呢?非常感谢.
我想知道如何将图像添加到MessageDialog框.我尝试了下面的代码,图像无处可寻
else if(button == B){
String text = "blahblahblahblahblah";
JTextArea textArea = new JTextArea(text);
textArea.setColumns(30);
textArea.setLineWrap( true );
textArea.setWrapStyleWord( true );
textArea.setSize(textArea.getPreferredSize().width, 1);
Font font = new Font("Verdana", Font.BOLD, 12);
textArea.setFont(font);
textArea.setForeground(Color.BLUE);
JOptionPane.showMessageDialog(
null, textArea, "Border States", JOptionPane.PLAIN_MESSAGE);
image2 = new ImageIcon(getClass().getResource("borderstates.jpg"));
label2 = new JLabel(image2);
add(label2);
Run Code Online (Sandbox Code Playgroud) 我一遍又一遍地试图找到解决这个问题的方法,但我似乎无法理解如何解决它.
我正在尝试编写一个简单的程序,在程序中绘制一个带有这些规范的圆圈:
不知何故,它不会绘制圆,并计算周长和面积.能帮我找到解决这个问题的方法吗?
这是我的代码:
-------主要-------
package circleSquarePackage;
import circleSquarePackage.Circle;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
public class CircleTester {
public static void main(String[] args)
{
JFrame frame = new JFrame();
// Display Circle in the frame
frame.setSize(600, 500);
frame.setTitle("CircleSquare");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create Circle Components
Circle round = new Circle();
frame.add(round);
frame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
--------其他类---------
package circleSquarePackage;
import javax.swing.JComponent;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Ellipse2D.Double;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import javax.swing.JOptionPane;
public class Circle extends JComponent {
// …Run Code Online (Sandbox Code Playgroud) 我需要从弹出的JOptionPane(或其他一些弹出窗口)中获取多行输入,但我的大部分搜索都指向那里,这是我被卡住的地方......).我坚持使用
JOptionPane.showInputDialog(null, new JTextArea(20,20));
Run Code Online (Sandbox Code Playgroud)
但我希望只将20x20区域读取到一个字符串,而不显示任何文本字段.我认为必须有一些方法可以做到这一点,但其他类型的对话框似乎只返回一个int ...它不一定是一个JOptionPane,只要它是一个单独的弹出窗口,我的主GUI可以读回一个字符串进行读取.
我收到错误:no suitable method found for showMessageDialog尝试自定义showMessageDialog按钮时说"开始"而不是OK.
这是代码:
JOptionPane.showMessageDialog(frame, radioPanel, "Start Game", JOptionPane.PLAIN_MESSAGE, null, new String[]{"Start"});
Run Code Online (Sandbox Code Playgroud)
有人可以指出为什么我可能会收到此错误.
提前致谢