Results 1 to 5 of 5
  1. #1
    JavaSwingUser is offline Member
    Join Date
    Feb 2015
    Posts
    3
    Rep Power
    0

    Default Eclipse plugin with Java Swing does not dispose (stabdAlone does)

    Hello All,

    I have developed a standAlone java swing program, which works completely as expected. But when I want to use it as a plugin, I am facing issues.

    1. When the user clicks the cancel button the GUI should close. I am using
    frame.setVisible(false);
    frame.dispose();
    in the actionListener of the button.

    But when user clicks on cancel button it throws a nullPointerException on frame.
    This is how my code is structured in the plugin Action. (I have used the Hello World sample template to build on my plugin)
    Java Code:
    public class SampleAction extends JFrame implements IWorkbenchWindowActionDelegate,ActionListener{
    
    SampleAction frame;
    private static JPanel contentPane;
    
    public SampleAction()  // constructor- defines the GUI structure
    {
    JPanel=.....
    JButton btnCancel= ......
     btnCancel.addActionListener(this);
    ---
    }
    public void run(IAction action) {
    		frame = new SampleAction();
    		frame.setVisible(true);
    	}
    @Override
    	public void actionPerformed(ActionEvent e) {
    ......
    if(buttonTitle.equals("Cancel"))
    {
    frame.setVisible(false); // place of exception
    frame.dispose();
    }


    Can anyone please help me with understanding why the frame object is not available in the actionPerformed () . ? How can I close my GUI on click on cancel button in Eclispe plugin?
    Last edited by JavaSwingUser; 02-18-2015 at 05:27 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    15

    Default Re: Eclipse plugin with Java Swing does not dispose (stabdAlone does)

    This code doesn't make a ton of sense. Why do you have an internal SampleAction variable? It would seem that the instance is already created by someone else, so this frame variable isn't doing what you think it is.

    When is the run() method called?
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Eclipse plugin with Java Swing does not dispose (stabdAlone does)

    The fact that contentPane is static is probably further proof that there is a bit of confusion going on with two different SampleAction instances.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    JavaSwingUser is offline Member
    Join Date
    Feb 2015
    Posts
    3
    Rep Power
    0

    Default Re: Eclipse plugin with Java Swing does not dispose (stabdAlone does)

    The run() method is automatically invoked when the plugin starts.
    Making the frame variable static actually worked.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Eclipse plugin with Java Swing does not dispose (stabdAlone does)

    Quote Originally Posted by JavaSwingUser View Post
    Making the frame variable static actually worked.
    But nobody suggested doing that, making it static is not fixing anything, it will in the end only make things worse as you will start to make your entire plugin static. I would rather that you remove the static keyword from that contentPane JPanel and then see what code breaks during compilation. That bit of code will probably be the biggest hint as to where the design flaw in your code is.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. [swing] JDialog.dispose() not working.
    By eramas in forum New To Java
    Replies: 1
    Last Post: 10-01-2012, 04:04 PM
  2. java swing plugin
    By zoheb.siddiqui in forum AWT / Swing
    Replies: 1
    Last Post: 03-03-2011, 04:37 PM
  3. Replies: 4
    Last Post: 12-21-2010, 03:26 PM
  4. Replies: 0
    Last Post: 12-16-2010, 10:14 AM
  5. Best eclipse plugin for Swing and AWT?
    By vsanandan in forum AWT / Swing
    Replies: 0
    Last Post: 12-03-2008, 06:35 AM

Tags for this Thread

Posting Permissions

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