joptionpane

When I try to use HTML with `JOptionPane`, HTML tags are printed instead of HTML formatting

瘦欲@ 提交于 2019-12-04 05:17:26
For some weird reason when I try to use HTML with JOptionPane , HTML tags are printed instead of HTML formatting. String msg = "Please fix <HTML><BODY BGCOLOR=#FFCCCC>this</BODY></HTML>"; JLabel message = new JLabel(msg); JOptionPane.showMessageDialog(MyApp.this, message, "Error!", JOptionPane.ERROR_MESSAGE); and the output is: Please fix <HTML><BODY BGCOLOR=#FFCCCC>this</BODY></HTML> mre The entire string needs to be enclosed within the HTML tags. For example: button = new JButton("<html><b><u>T</u>wo</b><br>lines</html>"); For more information, see How to Use HTML in Swing Components . Also

Java full screen exclusive mode

浪尽此生 提交于 2019-12-04 04:58:19
问题 I made my application to be full screen in exclusive mode but when I show an input dialog the application is minimized. I want the application to stay full screen and the input dialog to be show over it. This is how I render my application full screen: setUndecorated(true); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); gs.setFullScreenWindow(this); validate(); Edit: This is how I open the dialog: JOptionPane

JOptionPane and scroll function

浪子不回头ぞ 提交于 2019-12-04 02:35:17
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. GETah 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 Dimension( 500, 500 ) ); JOptionPane.showMessageDialog(null, scrollPane, "dialog test with textarea",

JOptionPane.showMessageDialog truncates JTextArea message

半世苍凉 提交于 2019-12-04 01:56:21
问题 My Java GUI application needs to quickly show some text to the end-user, so the JOptionPane utility methods seem like a good fit. Moreover, the text must be selectable (for copy-and-paste) and it could be somewhat long (~100 words) so it must fit nicely into the window (no text off screen); ideally it should all be displayed at once so the user can read it without needing to interact, so scrollbars are undesirable. I thought putting the text into a JTextArea and using that for the message in

How to close JOptionPane automatically?

梦想的初衷 提交于 2019-12-03 18:16:01
问题 I have a Thread running and in the time while the thread working i want to display a JOptionPane.showMessageDialog saying that the application is working and after thread is stopped, JOptionPane will close automatically and OK button will be deactivated the whole time. My Main code : class Index { public static void main(String args[]) { NewThread ob1 = new NewThread("One"); NewThread ob2 = new NewThread("Two"); NewThread ob3 = new NewThread("Three"); System.out.println("Thread One is alive:

How to handle cancel button in JOptionPane

こ雲淡風輕ζ 提交于 2019-12-03 12:15:39
I had created a JOptionPane of type showInputDialog . When it opens it, it shows me two buttons: OK and Cancel . I would like to handle the action when I push on Cancel button, but I don't know how to reach it. How can I get it? For example: int n = JOptionPane.showConfirmDialog( frame, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { } else if (n == JOptionPane.NO_OPTION) { } else { } Alternatively with showOptionDialog : Object[] options = {"Yes, please", "No way!"}; int n = JOptionPane.showOptionDialog(frame, "Would

Java: Custom Buttons in showInputDialog

南笙酒味 提交于 2019-12-03 10:20:29
How do you add custom text to the buttons of a JOptionPane.showInputDialog? I know about this question JOptionPane showInputDialog with custom buttons , but it doesn't answer the question asked, it just references them to JavaDocs, which doesn't answer it. Code So Far: Object[] options1 = {"Try This Number", "Choose A Random Number", "Quit"}; JOptionPane.showOptionDialog(null, "Enter a number between 0 and 10000", "Enter a Number", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, null); I would like to add a text field to this. You can use custom component instead

How to select an index value from a String Array in a JOptionPane

南楼画角 提交于 2019-12-02 20:19:37
问题 I've created a JOptionPane as a selection method. I want the int value for selection 1,2 or 3 of the String Array so I can use it as a counter. How do I get the index of the array and set it equal to my int variable loanChoice? public class SelectLoanChoices { int loanChoice = 0; String[] choices = {"7 years at 5.35%", "15 years at 5.5%", "30 years at 5.75%"}; String input = (String) javax.swing.JOptionPane.showInputDialog(null, "Select a Loan" ,"Mortgage Options",JOptionPane.QUESTION_MESSAGE

get JSlider's input and changes

偶尔善良 提交于 2019-12-02 19:25:21
问题 I need to use JSlider with getting input live, meaning that it will return an input without pressing any button. I have this piece of code for the slider: JPanel panel = new JPanel(); JSlider js = new JSlider(JSlider.VERTICAL, 0, 20, 10); js.setMajorTickSpacing(2); js.setPaintTicks(true); Hashtable labelTable = new Hashtable(); labelTable.put(new Integer(js.getMinimum()), new JLabel("x0")); labelTable.put(new Integer((js.getMinimum() + js.getMaximum()) / 2), new JLabel("x1")); labelTable.put

JOptionPane Multidimensional Array output

断了今生、忘了曾经 提交于 2019-12-02 17:45:44
问题 Ok say I have Multidimensional array that I want to display in JOptionPane.showMessageDialog . I know that when using System.out.println , you use a for loop. However the array size is determined by the user input, therefore I have to use a incrementor. For example: userinput[k] next to usernumber[k] then the next row would be userinput[k+1] next to usernumber[k+1] The trouble I am having is that by using my loop, it does each set one at a time in separate windows and not all together in a