Results 1 to 4 of 4
  1. #1
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Wink [SOLVED] Not dispose my JPanel

    Hi all,

    I've write some code to rendering some HTML code in a GUI. Here it is,

    Java Code:
        private JEditorPane editor = new JEditorPane();
        private JPanel mainPanel = new JPanel();
        private JButton exitButton = new JButton();
        private JDialog mainDialog = new JDialog();
    
        private HTMLRendering(String htmlText){
            editor.setEditorKit(new HTMLEditorKit());
            editor.setContentType("text/html");
            editor.setBorder(new BevelBorder(BevelBorder.LOWERED));
            editor.setEditable(false);
            editor.setText(htmlText);    // HTML code should be added here
            editor.addHyperlinkListener(this);
            
        // Exit button
            exitButton.setText("Exit");
            exitButton.setSize(new Dimension(65, 25));
            exitButton.setLocation(185, 215);
            exitButton.setBorder(new BevelBorder(BevelBorder.RAISED));
            editor.add(exitButton);
            exitButton.addActionListener(new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    if("Exit".equals(e.getActionCommand())){  // Newly added code segment
                        System.out.println("Exit clicked");
                        mainDialog.dispose();
                    }
                }
            });
    
            
            
        // Main panel
            mainPanel.setLayout(new BorderLayout());
            mainPanel.setPreferredSize(new Dimension(260, 250));
            mainPanel.add(editor);
        }
        
        private JPanel GetMainPanel(){
            return mainPanel;
        }
        
        public void CreateAndShowGUI(String htmlText){
            mainDialog.getContentPane().add(new HTMLRendering(htmlText).GetMainPanel());
            mainDialog.setResizable(false);
            //mainDialog.setUndecorated(false); // Changed in future
            mainDialog.pack();
            setWindowLocation();
            mainDialog.setVisible(true);
        }
    My question is that, on the click event mainPanel is not dispose. Only I want to dispose, not exist the system. I can exit from the system, not the dispose which I want to do.

    You guys have any idea why is that happened?

    Thanks

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Oops, I refer the wrong object here. I've solved it well. Thanks for spending your time to read this post.

  3. #3
    hr61283 is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Question dispoje JPanel....

    Hi..
    I am Also Interested to know how you disojed JPanel object without using System.exit(0);
    I am using application and in that i am using jdatechooser program using JPanel
    Once the date gets selected by user i want to dispoje the JPanel without exiting whole application....

    PLEASE REPLAY:confused::confused::confused::confused:

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    This is a very old thread. So why don't you start a new thread, in the relevant sub-forum with a better explanation about your requirements. Please don't post non-related questions in a forum.

Similar Threads

  1. refresh JPanel
    By olesja in forum AWT / Swing
    Replies: 1
    Last Post: 04-16-2008, 03:58 PM
  2. Genarate JPanel
    By Bill in forum AWT / Swing
    Replies: 6
    Last Post: 03-24-2008, 07:38 PM
  3. Problem with JPanel
    By ibanez270dx in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 05:04 PM
  4. JPanel Problems
    By Riftwalker in forum AWT / Swing
    Replies: 6
    Last Post: 10-15-2007, 11:16 PM
  5. Draw on JPanel, Help
    By carl in forum Java 2D
    Replies: 1
    Last Post: 07-31-2007, 06:56 AM

Posting Permissions

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