java - 带有“确定”按钮的消息框错误 - 字符串被截断

标签 java swing messagebox

在以下 Java 消息框示例应用程序中,“确定”按钮显示为三个点 (...)。它在 JDK 6.0 上运行正常。但是这个问题出现在JDK 7.0上。如何解决这个问题?

Java 源代码:

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class ShowDialogBox{
  JFrame frame;
  public static void main(String[] args){
  ShowDialogBox db = new ShowDialogBox();
  }

  public ShowDialogBox(){
  frame = new JFrame("Show Message Dialog");
  JButton button = new JButton("Click Me");
  button.addActionListener(new MyAction());
  frame.setLayout(new FlowLayout());
  frame.add(button);
  frame.setSize(400, 400);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  public class MyAction implements ActionListener{
  public void actionPerformed(ActionEvent e){
  JOptionPane.showMessageDialog(frame,"Eggs are not supposed to be green.","Inane warning",JOptionPane.WARNING_MESSAGE);
  }
  }
}

最佳答案

试试这个:

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class ShowDialogBox {

    private JFrame frame;

    public static void main(String[] args) {
        ShowDialogBox box = new ShowDialogBox();
    }

    public ShowDialogBox() {
        frame = new JFrame("Show Message Dialog");
        JButton button = new JButton("Click Me");
        button.addActionListener(new MyAction());
        frame.setLayout(new FlowLayout());
        frame.add(button);
        frame.setSize(400, 400);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    class MyAction implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JOptionPane.showConfirmDialog(frame,
                    "Eggs are not supposed to be green.", "Inane warning",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
        }
    }
}

关于java - 带有“确定”按钮的消息框错误 - 字符串被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20811234/

相关文章:

java - 在RecyclerView中实现 "add to favourite"机制

java - hashmap 如何提供恒定时间性能?

java - 添加新组件时如何在 jpanel 末尾设置滚动条

将 svg 文件读取为 BufferedImage 时出现 java.lang.NoClassDefFoundError

java - 多行 JTable 单元格在编辑期间不是多行的

python - 在 python 中获取屏幕顶部的 tkinter Messagebox

java - MQ系列9中的MQ初始上下文类

java - 在可见 fragment 的 popBackStack 之后调用哪个生命周期方法?

javascript - 如何使用Electron.js彼此相邻显示自定义Windows消息框按钮

python - 如何使用 tkinter 创建消息框?