Hello,
I've written the following code that invokes a JOPtionPane messageDialog, when the delete button is hit in the following frame and the selectedItem in the JComboBox is Default.
I want to change the JOPtionPane button name from OK to Close. Is there a way to do this with error message dialoges, as their is with confirmDialoges?
Please help out.
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class MyJOptionPaneTest {
public MyJOptionPaneTest()
{
JFrame frame = new JFrame("My Frame");
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
final JComboBox myComboBox = new JComboBox();
myComboBox.setPreferredSize(new Dimension(100,20));
myComboBox.getModel().setSelectedItem("Default");
myComboBox.addItem("Default");
myComboBox.addItem("Other");
JButton deleteButton = new JButton("Delete");
deleteButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(myComboBox.getSelectedItem().equals("Default"))
{
JOptionPane.showMessageDialog(null, "Default cannot be deleted", "Error", JOptionPane.ERROR_MESSAGE);
}
}
});
panel.add(myComboBox);
panel.add(deleteButton);
frame.getContentPane().add(panel);
frame.setSize(200,100);
frame.setResizable(false);
frame.setVisible(true);
}
public static void main(String [] args)
{
MyJOptionPaneTest test = new MyJOptionPaneTest();
}
}