Question

In the following java message box sample application, the "OK" button is appearing as three dots (...). It's working properly on JDK 6.0. But this problem arising on JDK 7.0. How to fix this issue?

Jave Source Code:

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);
  }
  }
}
Was it helpful?

Solution 2

It works fine for me, with JDK 7.0. Please make sure your JDK is not corrupted.

OTHER TIPS

try this:

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);
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top