1. DLP Flash Christmas Competition + Writing Marathon 2024!

    Competition topic: Magical New Year!

    Marathon goal? Crank out words!

    Check the marathon thread or competition thread for details.

    Dismiss Notice
  2. Hi there, Guest

    Only registered users can really experience what DLP has to offer. Many forums are only accessible if you have an account. Why don't you register?
    Dismiss Notice
  3. Introducing for your Perusing Pleasure

    New Thread Thursday
    +
    Shit Post Sunday

    READ ME
    Dismiss Notice

Java help

Discussion in 'Tech Support' started by Jamven, May 1, 2009.

  1. Jamven

    Jamven Headmaster DLP Supporter

    Joined:
    Nov 2, 2006
    Messages:
    1,120
    Location:
    Hunting Bullwinkle's assassin
    Ok, I am working on this program. It works so long as I do not add the code that I want to use to make a pop up dialog box.

    Basically, I have an array setup. I have it to were I can click a check box and a certain drawing will pop into view. On one of them, I want to use the following code to display Message Dialog box to show the user what is going on.

    JOptionPane.showMessageDialog(null, " Insert message once you get this fixed ", "Message Title", JOptionPane.INFORMATION_MESSAGE);

    This basically causes the program to freeze. Also, the pop up will not display the text that it should, "Insert message once you get this fixed "

    ----

    If I change the code to

    JOptionPane.showInternalMessageDialog(null, "information", "information", JOptionPane.INFORMATION_MESSAGE);

    I get the following error message

    Code:
    ----jGRASP exec: appletviewer jgrasphta.htm
    
    Exception in thread "AWT-EventQueue-1" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
        at javax.swing.JOptionPane.createInternalFrame(JOptionPane.java:1486)
        at javax.swing.JOptionPane.showInternalOptionDialog(JOptionPane.java:1259)
        at javax.swing.JOptionPane.showInternalMessageDialog(JOptionPane.java:1073)
        at javax.swing.JOptionPane.showInternalMessageDialog(JOptionPane.java:1047)
        at DrawingPanel.paintComponent(DrawingPanel.java:67)
        at javax.swing.JComponent.paint(JComponent.java:1027)
        at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
        at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:277)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
        at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    
    ----

    I am not really sure if that helps any.
     
  2. World

    World Oberstgruppenführer DLP Supporter Retired Staff

    Joined:
    Apr 19, 2006
    Messages:
    3,336
    Location:
    Axis of Evil (Original)
    The showInternalMessageDialog needs a parentFrame rather than null as a first parameter. Pass it your JFrame or, if you have multiple ones, the one on which coordinates the Message Dialog's position should be based on.
     
  3. Jamven

    Jamven Headmaster DLP Supporter

    Joined:
    Nov 2, 2006
    Messages:
    1,120
    Location:
    Hunting Bullwinkle's assassin
    Will this work for the "JOptionPane.showMessageDialog" as well?
     
  4. World

    World Oberstgruppenführer DLP Supporter Retired Staff

    Joined:
    Apr 19, 2006
    Messages:
    3,336
    Location:
    Axis of Evil (Original)
    The showMessageDialog shouldn't need a specific parent frame, only the ones with 'Internal' in the name. If it did, it would throw the same exception.

    Does the program freeze before or after this line? Maybe the error is before or after it. What text does the pop up display? Also, are there any error messages on the console?
     
  5. Jamven

    Jamven Headmaster DLP Supporter

    Joined:
    Nov 2, 2006
    Messages:
    1,120
    Location:
    Hunting Bullwinkle's assassin
    I forgot to say this, but thanks for your help World.

    ---

    The entire code can be found here

    http://forums.devarticles.com/java-development-38/freeze-on-running-194870.html

    I'll post the problem area here.

    Code:
    *snip*
    }
    if (checkBoxArray[2].isSelected())
    {
    //Entrance Perpendicular
    
    JOptionPane.showMessageDialog(null, "Entrance Perpendicular: Dr. S can input what he wants here ",
    "Entrance Perpendicular",
    JOptionPane.INFORMATION_MESSAGE);
    
    //TOP
    g.setColor(Color.BLACK);
    g.drawLine(325, 193, 335, 208);
    //Middle
    g.drawLine(325,250,335, 250);
    //BOTTOM
    g.drawLine(325, 305, 335, 295);
    
    }
    *snip*
    
    The program will run and I can check all of the check boxes until the I get to the one with the JOptionPane in it. It is more like it has gotten caught in an infinite loop or something. Except, I don't have 50 million popping up at once.

    I'll try to get some screens of the error code up in a minute.

    *edit*
    I am getting the following error code:

    *another edit*
    I was wrong about the 50 million pop ups

    Also, starting at

    at java.security.AccessController.doPrivileged(Native Method)

    it keeps repeating
    Code:
    	at java.awt.Dialog.show(Dialog.java:1101)
    	at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:853)
    	at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:650)
    	at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:621)
    	at DrawingPanel.paintComponent(DrawingPanel.java:67)
    	at javax.swing.JComponent.paint(JComponent.java:1027)
    	at javax.swing.JComponent.paintChildren(JComponent.java:864)
    	at javax.swing.JComponent.paint(JComponent.java:1036)
    	at javax.swing.JComponent.paintChildren(JComponent.java:864)
    	at javax.swing.JComponent.paint(JComponent.java:1036)
    	at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
    	at javax.swing.JComponent.paintChildren(JComponent.java:864)
    	at javax.swing.JComponent.paint(JComponent.java:1036)
    	at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
    	at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
    	at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
    	at java.awt.Container.paint(Container.java:1780)
    	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
    	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
    	at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
    	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
    	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
    	at java.awt.Dialog$1.run(Dialog.java:1051)
    	at java.awt.Dialog$3.run(Dialog.java:1103)
     
    Last edited: May 2, 2009
  6. World

    World Oberstgruppenführer DLP Supporter Retired Staff

    Joined:
    Apr 19, 2006
    Messages:
    3,336
    Location:
    Axis of Evil (Original)
    Hm, I'm afraid I can't help you there. Applets aren't my cup of tea, haven't used them in years. What I was able to find out by trying that code was that while the MessageDialog isn't drawn, you can still click on the invisible OK-Button (or hit enter or space).

    I can tell you though that the MessageDialog would be called whenever you change something as long as the corresponding checkbox was ticked since that part of the paintComponent method would be called every time.

    This shows itself especially if you don't use HTML as an applet viewer. If I try to resize the Applet Viewer Window with the option checked, I get a StackOverflow from the many MessageDialogs that pop up.

    In short, I have no idea how the OptionPanes work in Applets.
    All I can recommend is not using an OptionPane and painting a custom message box over the paint area and put the program to sleep for a few seconds. Or maybe draw a String with the message somewhere.
     
  7. Jamven

    Jamven Headmaster DLP Supporter

    Joined:
    Nov 2, 2006
    Messages:
    1,120
    Location:
    Hunting Bullwinkle's assassin
    g.drawString seems to be working at the moment

    Thanks again for your help, World
     
Loading...