joptionpane

Pressing Yes/No on embedded JOptionPane has no effect

南楼画角 提交于 2019-12-11 07:54:45
问题 I'm trying to add an exit confirmation check to JFrame but I want the dialog to be undecorated. I've figured I need to use custom JDialog and custom JOptionPane. frame.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { JDialog dialog = new JDialog(); dialog.setUndecorated(true); JOptionPane pane = new JOptionPane("Are you sure that you want to exit?", JOptionPane.QUESTION_MESSAGE,JOptionPane.YES_NO_OPTION);

Having trouble with JOPtionPane

我的梦境 提交于 2019-12-11 07:19:34
问题 I'm a beginner to Java and I'm having some difficulty with a problem. I am using JOPtionPane to ask the user some questions. However, my difficulties are coming from the fact that I don't know how to handle exceptions properly when the user clicks the X or cancel anywhere in the program. Also, when I looked at the Java API and saw how to implement titles, I tried it but now what should be titles are being placed in the text field instead. Quitting from other parts of the program also yields

JOptionPane cancel button

让人想犯罪 __ 提交于 2019-12-11 07:03:36
问题 Guys Im trying to use the JOptionPane but the cancel button is responding as if I entered a wrong input value and does not exit the programm. Any ideas whould be very useful! int n = 0, k = 0; Students stu = new Students(); while (n <= 0) { try { n = Integer.parseInt(JOptionPane.showInputDialog(stu, "Enter the number of people","Input", JOptionPane.INFORMATION_MESSAGE)); if (n <= 0) { OptionPane.showMessageDialog(stu, "You have given a wrong input!", "Warning", JOptionPane.WARNING_MESSAGE); }

Return Value from JOptionPane indicating the button selected

给你一囗甜甜゛ 提交于 2019-12-11 06:47:09
问题 I have made an option panel, but I can't get the buttons to actually do as they are meant to. I have tried to make action an int which is connected to the panel, but that doesn't work. Object[] choices = null; Object[] options = { "Criticals", "Pure Damage", "Heal 300 points", "Flee" }; JOptionPane.showOptionDialog(null, "What will you do?", "action", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); switch (action) { case 0: int Criticals = (int) (Math

Data validation with JOptionPane

拟墨画扇 提交于 2019-12-11 05:19:59
问题 I want to perform data validation while JOptionPane.I found the following approach but i am not really satisfied with it import javax.swing.*; import java.util.regex.*; public class ValidateJOptionPane { public static void main(String[] args) { String input = JOptionPane.showInputDialog("Enter number: "); Pattern p = Pattern.compile("[A-Z,a-z,&%$#@!()*^]"); Matcher m = p.matcher(input); if (m.find()) { JOptionPane.showMessageDialog(null, "Please enter only numbers"); } } } It would have been

JOptionPane and Scanner input issue

旧城冷巷雨未停 提交于 2019-12-11 03:46:43
问题 I'm writing a program where at one point, I need to print a String on a window using JOptionPane. The code for the line looks something like this: JOptionPane.showMessageDialog(null, "Name: " + a.getName()); The getName function refers to the object a that i created that has a method that returns a String. However, when my code reaches this point, the program appears to enter some kind of infinite loop as the window never pops up and when using debug, it appears never-ending. The main thing

Java Swing: Get text value from JOptionPane

£可爱£侵袭症+ 提交于 2019-12-11 03:13:00
问题 I'd like to create a new window which is used in POS system. The user input is for an amount of money the customer has and the window has to display the exchange amount. I'm new with JOptionPane feature (I have been using JAVAFX and it's different). This is my code: public static void main(String[] argv) throws Exception { String newline = System.getProperty("line.separator"); int cost = 100; int amount = Integer.parseInt(JOptionPane.getText()) // this is wrong! This needs to come from user

Java GUI - JOptionPane/JDialog customization issue

℡╲_俬逩灬. 提交于 2019-12-11 02:35:59
问题 So I'm trying to make a simple dialog where the user can input some information... My problem is that I'm trying to make the whole background white; I got MOST of it, but there's a gray line behind the buttons that I don't know how to fix (make white as well). How can I fix it? :( What it looks like: What I want: Code: JPanel all = new JPanel(); all.setLayout(new BorderLayout()); all.add(names, BorderLayout.NORTH); all.add(academic, BorderLayout.CENTER); all.setBackground(Color.WHITE); all

JTextField scroll

本秂侑毒 提交于 2019-12-11 01:12:35
问题 Im making this program for fun and i got stuck because the program was running off the screen. how do i implement a scroll bar without having to change my code completely. public static void main(String args[]) throws IOException { String ai,ia,ny; JTextField field1 = new JTextField(); JTextField field2 = new JTextField(); JTextField field3 = new JTextField(); JTextField field4 = new JTextField(); JTextField field5 = new JTextField(); JTextField field6 = new JTextField(); JTextField field7 =

Postpone Event Queue after Focus Lost

眉间皱痕 提交于 2019-12-11 01:08:40
问题 I have a JTable with a custom cell editor. The editor implements FocusListener so I can check if the cell's contents is valid if the user clicks away from the cell. I'd like to use a JOptionPane within focusLost (in the EventDispatchThread ) to allow the user to select whether to revert to an old value or accept an adjusted value. Here's the problem; if the user is editing a cell, then clicks a button away from the table, the button's actionlisteners are alerted before JOptionPane has