joptionpane

How do I show only the first letters of a string?

浪子不回头ぞ 提交于 2019-12-20 08:14:09
问题 I'm prompting the user to enter their first and last name but I can't figure out how to show just their first and last initials import javax.swing.*; //import java.awt.*; public class Lab2Program2 { public static void main (String [] args) { String firstName; String lastName; firstName = JOptionPane.showInputDialog(null, "What is your first name?"); lastName = JOptionPane.showInputDialog(null, "What is your last name?"); JOptionPane.showMessageDialog(null, " Your initials are " + firstName +

JOptionPane in Java

筅森魡賤 提交于 2019-12-20 03:42:14
问题 Does anyone know why tab (\t) does not work with JOptionPane.showMessageDialog? My code is as follows: String addText = "NAME\t\tADDRESS\t\tTEL.No\tEMAIL\n"; for (int i = 0; i < addressBookSize; i++) { addText = addText+entry[i].viewAllInfo(); } System.out.print(addText); JOptionPane.showMessageDialog(null, addText); Are there other ways to align text in JOptionPane? 回答1: Put your tabbed text into JTextArea String addText = "NAME\t\tADDRESS\t\tTEL.No\tEMAIL\n"; for (int i = 0; i <

showOptionDialog buttons on separate lines

穿精又带淫゛_ 提交于 2019-12-20 03:01:13
问题 can't get the buttons in the OptionDialog to appear on a new line. They all appear in one row, but I'd like to have them on separate lines. I also tried setting up a frame to add to the OptionDialog (to set the max width), but it didn't work out for me either. Any ideas/help/suggestions appreciated. Object[] options = { "Button1", "Button2", "Button3", "Button4", "Button5 On a newLine\n\n", "Button 6", "Button 7" }; int x = JOptionPane.showOptionDialog(null, "Choose a button..", "Title",

JOptionPane title bar icon

余生颓废 提交于 2019-12-20 02:49:12
问题 I'd like to replace the icon in a JOptionPane title bar (as it currently shows the default Java coffee logo). I tried the following: JOptionPane.showMessageDialog(null, "Some Text", "Login", JOptionPane.INFORMATION_MESSAGE, ImageCacheProvider .instance.getImageIcon("img/an image.png")); It replaces the icon in the window but not the one in the title bar: Is there any approach to change the icon in the title bar or alternatively to hide the default Java icon without having to implement a

show multiple MessageDialog at a time

只愿长相守 提交于 2019-12-20 02:47:10
问题 I am trying to make a program that displays 3 MessageDialog boxes at a time. I thought that if you put JOPtionPane.showMessageDialog in an actionListner class for a swing timer , it would show a new MessageDialog box every second. So here is the code that I came up with: package pracatice; import java.awt.event.*; import javax.swing.*; public class practice extends JFrame { public static int num = 0; public static TimerClass tc = new TimerClass(); public static Timer timer = new Timer(1000,

Creating a custom blocking Java Swing prompt

与世无争的帅哥 提交于 2019-12-19 17:47:22
问题 This problem is solved. I'm am developing a Java Swing based projected, and the look & feel of the application is completely customized. We are trying to maintain a consistent appearance throughout the program, and the default Java dialog windows are not the same. The current issue requires a control blocking call to the user prompt. Similar to JOptionPane.showConfirmDialog() In this case, the static call produces a window, and halts the flow of the program until the user selects an option.

Changing the icon in JOptionPane

杀马特。学长 韩版系。学妹 提交于 2019-12-19 11:20:07
问题 I have a class that extends JOptionPane . In it there's a method that calls showConfirmDialog (new JFrame(), (JScrollPane) jp, "Friends List", 2, 0, icon); Is there a way to change the icon without having to call showConfirmDialog a second time? That is, based on my input in the JOptionPane , can I change the icon without making a new confirm dialog? 回答1: As shown here, you can add a JOptionPane to a Dialog and listen for the desired PropertyChangeEvent . The example below switches between

making a JPanel into a JOptionPane.OK_OPTION

 ̄綄美尐妖づ 提交于 2019-12-19 09:47:04
问题 currently i have a class which extends JPanel and basically shows some information about an object passed into its constructor. There are various labels and Image icons on the screen and has a BorderLayout set. This panel is triggered when the user left clicks on an ImageIcon from the main GUI and shows up on the screen. i was wondering, how (if there is a way) i could implement the JOptionPane.OK_OPTION onto the whole Panel so that i dont have to close the panel using Event handling, as the

User input validation for JOptionPane.showInputDialog

感情迁移 提交于 2019-12-19 07:54:39
问题 I'm just learning JAVA and having a bit of trouble with this particular part of my code. I searched several sites and have tried many different methods but can't seem to figure out how to implement one that works for the different possibilities. int playerChoice = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter number for corresponding selection:\n" + " (1) - ROCK\n (2) - PAPER\n (3) - SCISSORS\n")) - 1; I imagine I need to have some type of validation even for when the user has no

Clicking the cancel button showInputDialogue

青春壹個敷衍的年華 提交于 2019-12-19 06:00:42
问题 I have a question in regards to pressing the cancel button of my inputDialoguebox. I have asked a similar question before so I apologize if I seem to repeat myself. The main problem I have is that my code executes regardless of me pressing cancel and a socket connection does get made even if I don't add any input. Why does this happen and how can I avoid this? String input = ""; try { InetAddress host = InetAddress.getLocalHost(); String hostAddress = host.getHostAddress(); //setting label to