joptionpane

JOptionPane.showMessageDialog wait until OK is clicked?

我怕爱的太早我们不能终老 提交于 2019-12-07 05:34:06
问题 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

JOptionPane showConfirmDialog with only one button

限于喜欢 提交于 2019-12-06 17:39:21
问题 I need to have only one button in showConfirmDialog . I tried this: int response = JOptionPane.showConfirmDialog(null, "Time Entered Successfully", "", JOptionPane.OK_OPTION, JOptionPane.PLAIN_MESSAGE); if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.OK_OPTION) { System.out.println("CLOSING>>>>>>"); } But this shows dialog with Yes_No_option. I want only OK button to be displayed there. Is it possible? 回答1: I want only OK button to be displayed there. Is it possible? Use

How do I create a JOptionPane.showOptionDialog box in Java (Swing) with custom JButtons?

若如初见. 提交于 2019-12-06 11:52:53
After reading through all the Dialog tutorials for a while, there seems to be no apparent way to do this. The closest thing seems to be JOptionPane.showOptionDialog , but I am limited by the optionType parameter here. EDIT: I figured out the problem, but have a new one. It seems that the options parameter being specified in showOptionDialog needs to be fairly simple objects (strings or just 'objects', not JButton or the like). I was trying to put an array of custom-factory-created JButtons here, because they have a special rollover icon that I want to be using. What happens, though, is that

JOptionPane displays behind the parent JFrame

别等时光非礼了梦想. 提交于 2019-12-06 08:06:34
I created a swing application on Windows OS. One of my JDialog (whose window is parentJFrame) shows a JOptionPane. JOptionPane.showMessageDialog(parentJFrame, "I am a JOption"); . At the run time, the parentJFrame setAlwaysOnTop(true) . Even though it has set alwaysOnTop-TRUE, the JOptionPane appeares on the parentJFrame on Windows OS. but When I ran it on Linux OS,JOptionPane displays behind the parentJFrame.(May be the reason is that parentJFrame alwyasOnTop is true , but how JRE runs the same application in different ways for diffrent OS s ?) How can I get it on the top of parentJFrame in

How to validate if Text entered is a numeric number?

本秂侑毒 提交于 2019-12-06 06:11:05
I have a calculation application which I need to validate the fields to check if the values entered are numeric numbers and not alphanumeric. I have some ideas about the codes. Please guide me if I have done anything wrong or seem noob as this is my first time trying out Swing. private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) { String text1 = jTextField1.getText(); // TODO add your handling code here: } private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) { String text2 = jTextField2.getText(); // TODO add your handling code here: } private void

Java return from a ShowOptionDialog from an inner JPanel

China☆狼群 提交于 2019-12-06 02:41:36
I used JOptionPane.showOptionDialog(null, new MyPanel(), "Import", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{}, null); because I don't want the default buttons provided by the OptionDialog and I created my buttons inside the MyPanel extends JPanel So my problem is now how can I close that OptionDialog from inside the MyPanel fired by an ActionEvent ? I don't care the return value, as long as that dialog disappears. And I realize this might not be the best design but I've been working on this for a lot of times so I'd prefer a fix that involves as little change

JOptionPane and scroll function

て烟熏妆下的殇ゞ 提交于 2019-12-05 20:15:13
问题 I want to JList a lot of results in a JOptionPane, however, I'm not sure how to add in a scroll function should there be too many results. How would I add a scroll bar to a JOptionPane? Any help would be great. Thanks. 回答1: Here is an example using a JTextArea embedded in a JScrollPane : JTextArea textArea = new JTextArea("Insert your Text here"); JScrollPane scrollPane = new JScrollPane(textArea); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); scrollPane.setPreferredSize( new

Custom dialog using JOptionPane API won't dispose

帅比萌擦擦* 提交于 2019-12-05 18:55:07
I've been just playing with JOptionPane API to show a custom dialog and I've found a strange situation: when I choose either OK or Cancel option or press Esc key this dialog won't dispose as expected. The thing is, instead of using this single line to display a modal dialog: JOptionPane.showConfirmDialog( null , "The quick brown fox jumps over the lazy dog." , "New Dialog" , JOptionPane.OK_CANCEL_OPTION , JOptionPane.PLAIN_MESSAGE); I wanted to use the API, setting all the parameters one by one and displaying a dialog as shown in the docs (see Direct Use section): JOptionPane pane = new

Custom Cursor in a Swing JDialog

假如想象 提交于 2019-12-05 12:46:09
I have a Java Swing application, developed on Mac OS X 10.5 using Java 1.5. I'm trying to make a custom cursor appear when the user moves the mouse over some text in a dialog. The cursor never changes, though. When I don't use a JFrame instead of a JDialog, the cursor does change. But then I'll have to write all the dialog code myself. How can I get the cursor to appear? Here's the simplest code I could create to demonstrate the problem: import javax.swing.*; import java.awt.*; public class CursorTest { public static void main(String[] args) { JLabel label = new JLabel("Move mouse here for

JOptionPane.YES_OPTION == ENTER on each button

爷,独闯天下 提交于 2019-12-05 12:26:12
I have a option dialog like this: 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 } When I used mouse and press Yes/No - all work fine... But when I start use keyboard, press TAB to go to "No" button, and then press ENTER - work "Yes" option It all depends on the look 'n