Results 1 to 3 of 3
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default [SOLVED] a modeless dialog?

    Consider the following snippet:

    Java Code:
    Consider this code snippet:
    
    import javax.swing.*;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    
    @SuppressWarnings("serial")
    public class AboutDialog extends JDialog {
    	public AboutDialog(JFrame owner)
    	{
    		super(owner, "About Dialog Test", true);
    		add (new JLabel ("<html><h1><i>Core Java</i></h1></html>",
    				BorderLayout.CENTER));
    		
    		final JPanel panel = new JPanel(); 
    [B]/*why does this have to be final?  
    what if I want to set panel to another value?[/B]
    */
    		final JButton ok = new JButton("Ok"); [B]same as for panel[/B]
    		
    		ok.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent event)
    			{
    				setVisible(false);
    				panel.add(ok);
    				add(panel, BorderLayout.SOUTH); [B]//here I'm getting an error The constructor JLabel(String, String) is undefined.
    This is misleading, because I have passed an (HTML) string, and, an integer.[/B]
    				
    				setSize(250,150);
    			}
    		});
    	}
    
    }
    Environment notes:
    1. Microsoft Windows [Version 6.0.6001]
    Copyright (c) 2006 Microsoft Corporation. All rights reserved.

    C:\Users\Administrator>java -version
    java version "1.6.0_13"
    Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
    Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

    2. Using Eclipse I get the above errors.

    3. Using Textpad I get the following error:
    C:\Users\Administrator\Documents\Java Source Code\AboutDialog.java:10: cannot find symbol
    symbol : constructor JLabel(java.lang.String,java.lang.String)
    location: class javax.swing.JLabel
    add (new JLabel ("<html><h1><i>Core Java</i></h1></html>",
    ^
    1 error

    Tool completed with exit code 1


    4. Related links:
    The New Modality API in Java SE 6
    Last edited by jon80; 05-29-2009 at 03:06 PM.

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    you're looking in the wrong place.
    your err comes from this:
    Java Code:
    super(owner, "About Dialog Test", true);
    add (new JLabel ("<html><h1><i>Core Java</i></h1></html>",
    				BorderLayout.CENTER));
    which should be:
    Java Code:
    add (new JLabel ("<html><h1><i>Core Java</i></h1></html>"[B])[/B], // <-- added ')'
    				BorderLayout.CENTER); // <-- removed ')'
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    final JPanel panel = new JPanel();
    /*why does this have to be final?
    what if I want to set panel to another value?
    */
    it must be final in order for the inner class to use it. Otherwide, you should have made it a field instead.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. JColorChooser modeless - Event Listener problem
    By siamino in forum New To Java
    Replies: 1
    Last Post: 04-14-2009, 01:39 AM
  2. Dialog
    By JavaLerner in forum AWT / Swing
    Replies: 27
    Last Post: 07-07-2008, 12:29 PM
  3. Example of SWT Dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-09-2008, 01:01 PM
  4. Dialog Box
    By uncopywritable in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 01:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •