Results 1 to 6 of 6

Thread: How to use JDialog class?

  1. #1
    Join Date
    Dec 2009
    Posts
    37

    How to use JDialog class?

    Hello friends,

    I have completed core java programming and just started advanced java programming. The advanced java programming seems more complicated than core java programming. I am not able to understand the 'JDialog class' of java. I don't have any idea about this java class. Please let me know something about this 'JDialog class' of java. Also provide suitable example for 'JDialog class'. I will appreciate your help.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: How to use JDialog class?

    The JDialog class is the main class for creating a dialog window. You can use this class to create a custom dialog, or invoke the many class methods in JOptionPane to create a variety of standard dialogs. The JDialog component contains a JRootPane as its only child. The contentPane should be the parent of any children of the JDialog. The same principle holds true for setting layout managers, removing components, listing children, etc. All these methods should normally be sent to the contentPane instead of to the JDialog.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to use JDialog class?

    Hi,

    Following example of java will depict you the use of JDialog class
    Code:
    import javax.swing.JDialog;
    import javax.swing.JPanel;
    
    public class AboutDialogDM extends JDialog implements ActionListener 
    {
      public AboutDialog(JFrame parent, String title, String message) {
        super(parent, title, true);
        if (parent != null) {
          Dimension parentSize = parent.getSize(); 
          Point p1 = parent.getLocation(); 
          setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4);
        }
        JPanel messagePane01 = new JPanel();
        messagePane01.add(new JLabel(message));
        getContentPane().add(messagePane01);
        JPanel button01Pane01 = new JPanel();
        JButton button01 = new JButton("OK"); 
        button01Pane01.add(button01); 
        button01.addActionListener(this);
        getContentPane().add(button01Pane01, BorderLayout.SOUTH);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        pack(); 
        setVisible(true);
      }
      public void actionPerformed(ActionEvent e) {
        setVisible(false); 
        dispose(); 
      }
      public static void main(String[] abn) {
        AboutDialog dlg1 = new AboutDialog(new JFrame(), "title", "message");
      }
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: How to use JDialog class?

    I suggest you to refer following constructors of JDialog class, which are very useful while using it's properties:
    • JDialog(Frame ownr, String ttl, boolean mdl, GraphicsConfiguration grcn)
    • JDialog(Frame ownr, String ttl, boolean mdl)
    • JDialog(Frame ownr, String ttl)
    • JDialog(Frame ownr, boolean mdl)
    • JDialog(Dialog ownr, String ttl, boolean mdl, GraphicsConfiguration grcn)

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to use JDialog class?

    Please review below example of JDialog class:
    Code:
    class HelpDM extends JDialog 
    {
      Help(Frame frm, String title) 
    {
        super(frm, title);
        setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
    
        try {
          JEditorPane ep1 = new JEditorPane("file:///" + new File("").getAbsolutePath() + "/uchelp.html");
          ep1.setEnabled(false);
          getContentPane().add(ep1);
        } 
       catch (IOException ioe) {
          JOptionPane.showMessageDialog(frame, "Unable to install editor pane");
          return;
        }
    
        setSize(300, 200);
        setLocationRelativeTo(frm);
        setVisible(true);
      }
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: How to use JDialog class?

    Please study following methods of JDialog class, which will give you something idea about it's use:
    1. setRootPaneCheckingEnabled(boolean bln)
    2. setLayout(LayoutManager lytmanager)
    3. setJMenuBar(JMenuBar jmnu)
    4. setGlassPane(Component glsPane)
    5. setDefaultLookAndFeelDecorated(boolean defaultFeelDecorated)
    6. setContentPane(Container contentPn)

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  3. Remove The Title Bar Of A JDialog
    By ramsun in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 01:07 PM
  4. How to Call a JDialog from a JInternalFrame?
    By Bhardwaj in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 01:27 PM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,861,264.53503 seconds with 16 queries