joptionpane

Setting Mnemonics and Hot Keys for a JOptionPane Dialog

核能气质少年 提交于 2019-12-05 11:49:35
Is it possible to assign hotkeys and mnemonics to the buttons in a JOptionPane Dialog? I'd like to be able, in a JOptionPane generated message dialog with the options Yes, No and Cancel, press Y to hit the Yes button, N to hit the No button and escape to activate the escape button. Similarly in a dialog with Okay and Cancel buttons I'd like to be able to activate them with enter and escape. I've attempted passing JButtons into the JOptionPane's button Object array with the Mnemonics set already. The mnemonics work and the buttons show up correctly in the dialogs, however, they do not act

JOptionPane.showMessageDialog wait until OK is clicked?

放肆的年华 提交于 2019-12-05 11:22:37
This might be a very simple thing that I'm overlooking, but I just can't seem to figure it out. I have the following method that updates a JTable: class TableModel extends AbstractTableModel { public void updateTable() { try { // update table here ... } catch (NullPointerException npe) { isOpenDialog = true; JOptionPane.showMessageDialog(null, "No active shares found on this IP!"); isOpenDialog = false; } } } However, I don't want isOpenDialog boolean to be set to false until the OK button on the message dialog is pressed, because if a user presses enter it will activate a KeyListener event on

How can I add a listener on the ok button of JOptionPane? [duplicate]

删除回忆录丶 提交于 2019-12-05 06:08:54
This question already has an answer here: Java Dialog - Find out if OK is clicked? 4 answers How can I add a listener on the click of "OK" button of JOptionPane.INFORMATION_MESSAGE . My JOptionPane is: JOptionPane.showMessageDialog(null, "Your password is: " + password, "Your Password", JOptionPane.INFORMATION_MESSAGE); The showMessageDialog method returns void when the user closes or clicks ok. But you can use the method JOptionPane.showOptionDialog with a single DEFAULT_OPTION for the OK button. The showOptionDialog will return 0 if OK was clicked and -1 if the user closed the dialog. int

Java console loop

断了今生、忘了曾经 提交于 2019-12-05 02:55:32
问题 Noticed no one has answered this yet on here so thought I'd give it a shot again. Hopefully someone can help. Already went to my Java teacher and he just said I messed something up and couldn't figure it out so I can't move on. Anywho, here's my test code: import javax.swing.JOptionPane; public class Test { public static void main(String[] args) { System.out.println("hello"); JOptionPane.showInputDialog("Enter a real number"); } } And this is what I receive in console: hello 03:30.28 1[dbg]

“Un-rollover” a JButton when a JOptionPane is displayed

让人想犯罪 __ 提交于 2019-12-05 02:50:47
I have a situation where I need to display a JOptionPane after clicking on a JButton. The JButton has a default icon, and a rollover icon (which displays when, well, the mouse rolls-over the button). However, once the button is clicked and a JOptionPane appears, the rollover icon does not change back to the original, and continues to remain so until the user brings the mouse back to the JButton's frame after selecting an appropriate JOptionPane choice. How would I "un-rollover" the JButton when it is clicked and the JOptionPane is displayed? TL;DR : JButton displays rollover icon even when

Adding a new WindowListener to a JFrame

为君一笑 提交于 2019-12-05 01:52:16
问题 mainFrame.addWindowListener(new WindowListener() { @Override public void windowClosing(WindowEvent e) { if (JOptionPane.showConfirmDialog(mainFrame, "Are you sure you want to quit?", "Confirm exit.", JOptionPane.OK_OPTION, 0, new ImageIcon("")) != 0) { return; } System.exit(-1); } @Override public void windowOpened(WindowEvent e) {} @Override public void windowClosed(WindowEvent e) {} @Override public void windowIconified(WindowEvent e) {} @Override public void windowDeiconified(WindowEvent e

I would like to change this code to display only “OK” and delete the cancel button

我们两清 提交于 2019-12-04 06:57:49
问题 I would like to change this code to display only "OK" and delete the cancel button. Object contestacion5 = JOptionPane.showInputDialog(null, "#5 Que describe mejor a la Norteña?", "Examen Tijuanas PR", //3 JOptionPane.DEFAULT_OPTION, null, new Object[] {"Ensalada de espinacas, tomates, zetas, cebolla, tocineta, aguacate, queso de hoja y tiras de maiz crujientes en vinagreta de la casa.", "Lechuga romana servida con tomate, cebolla, maiz, aguacate, queso de hoja y tiritas de maiz crujientes

Alternative to calling a static method via an instance

落花浮王杯 提交于 2019-12-04 06:44:09
问题 JOptionPane jop = new JOptionPane( ); jop.showMessageDialog(“This is never done”); I'm told that this is done in poor taste. I mean it works, but apparently a "pro" would not do it thus as showMessageDialog is static. Is there a better way to write this? 回答1: A static method can be invoked without a reference to an instance: JOptionPane.showMessageDialog("This is never done"); Actually, these line: JOptionPane jop = new JOptionPane(); jop.showMessageDialog("This is never done"); will be

White bars in the right and bottom sides of a canvas after a JOptionPane confirmDialog?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 05:52:01
问题 So guys, using a JOptionPane to ask the user if the app should update or not, and after which I get these white bars in the bottom and right sides of my canvas. Tried removing the autoupdate thing and works fine. Here's my code GameUtils.init(); String version = AutoUpdate.checkForUpdates(); if (Double.parseDouble(version) > AutoUpdate.VERSION) { AutoUpdate.update(version); JFrame frame = null; try { frame = new JFrame(GameUtils.data.getString("title")); } catch (JSONException e) { e

Align text to the right in JOptionPane

跟風遠走 提交于 2019-12-04 05:28:54
问题 Is it possible to align the text to the right in JOptionPane? (I don't want to use JDialog) because I want to write some sentences in Arabic 回答1: Create a JPanel, align your text in your JPanel and then add the JPanel as the Object parameter of the JOptionPane. Or use a JDialog (why the desire not to use one of these?). 回答2: String message = "<html><body><div width='200px' align='right'>This is some text!</div></body></html>"; JLabel messageLabel = new JLabel(message); JOptionPane