Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: "Widget is disposed" LMDE

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question "Widget is disposed" LMDE

    Hi all, I'm newb & I know it. Stuck at some trouble doing my learning activities. The task is, find out whether the given string is a palindrome. All but one work fine.
    The problem is: the main window's opened, I put the string into, then press "Check" and an answer window opens. Then I press OK in the answer window. And if I try to put another string into the main window and press Check again - the whole thing crashes. I have to close it and start again if I wanna reuse it. So I think I got a dumb piece of code somewhere in my program. What's the hitch?
    (PS sry for poor Eng, it's not my mt)
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.swt.widgets.Label;
     
    public class PalindromeCheck {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
                    Display display = new Display();
                    Shell shell = new Shell(display);
                    shell.setText("Palindrome check");
                    shell.setSize(255,150);
                    shell.setMinimumSize(255,150);
                    shell.open();
                    final Button checkme = new Button(shell,SWT.PUSH);
                    checkme.setText("Check string");
                    checkme.setBounds(55,50,140,60);
                    final Text checkit = new Text(shell,SWT.SHADOW_IN);
                    checkit.setBounds(10,10,230,30);
                    final Shell dialog = new Shell(shell,SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
                    dialog.setSize(250,100); dialog.setMinimumSize(250,100);
                    final Label result = new Label(dialog,SWT.NONE);
                    result.setBounds(10,10,230,30);
                    final Button ok = new Button(dialog,SWT.PUSH);
                    ok.setBounds(105,35,35,30);
                    ok.setText("OK");
     
                    Listener dialoglistener = new Listener() {
            	        public void handleEvent(Event event) {
    	        	        dialog.close();
    	                }
                    };
                    ok.addListener(SWT.Selection,dialoglistener);
     
                    Listener checkmelistener = new Listener() {
    	                public void handleEvent(Event event) {
    	                	boolean answer=true;
    	                	String check = checkit.getText();
     
    	        	        for (j=0; j <= ((check.length() - 1) - j); j++) {
    		                	String a = Character.toString(check.charAt(j));
    		                	String b = Character.toString(check.charAt((check.length() - 1) - j));
    		                	if (a.compareToIgnoreCase(b) != 0) {
    		                		answer=false; break;
    		                	}
    		                }
    		                result.setText((answer) ? "The string is a palindrome indeed!" : "The string is not a palindrome!");
    		                dialog.open();
    	                }
                    };
                    checkme.addListener(SWT.Selection,checkmelistener);
     
                    while (!dialog.isDisposed()) {
                            if (!display.readAndDispatch()) display.sleep();
                    }
     
                    while (!shell.isDisposed()) {
                            if (!display.readAndDispatch()) display.sleep();
                    }
                    display.dispose();
    	}
    }

    i got the following when it crashes:
    Exception in thread "main" org.eclipse.swt.SWTException: Widget is disposed
    at org.eclipse.swt.SWT.error(SWT.java:4361)
    at org.eclipse.swt.SWT.error(SWT.java:4276)
    at org.eclipse.swt.SWT.error(SWT.java:4247)
    at org.eclipse.swt.widgets.Widget.error(Widget.java:4 80)
    at org.eclipse.swt.widgets.Widget.checkWidget(Widget. java:417)
    at org.eclipse.swt.widgets.Label.setText(Label.java:5 71)
    at PalindromeCheck$2.handleEvent(PalindromeCheck.java :56)
    at org.eclipse.swt.widgets.EventTable.sendEvent(Event Table.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.ja va:1276)
    at org.eclipse.swt.widgets.Display.runDeferredEvents( Display.java:3554)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Di splay.java:3179)
    at PalindromeCheck.main(PalindromeCheck.java:67)
    Last edited by Scampada; April 13th, 2013 at 11:03 AM. Reason: added nested formatting
    So treat me nice


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "Widget is disposed" LMDE

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    The code uses 3rd party packages and classes which will reduce the number of people that can compile and execute the code for testing.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Widget is disposed" LMDE

    Aw. Yeah. I didn't noticed the formatting was lost. And in the "Ask a question" form were not formatting buttons. Now trying to get the "Edit post" link working... Waiting for 5 minutes and no reaction from it
    So treat me nice

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "Widget is disposed" LMDE

    Could be some restriction for new posters. Many OPs just post again with the code tags. I've added code tags.


    However that did not fix the formatting. The nested statement need to be indented. Too many start in the first column.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Widget is disposed" LMDE

    I bothered to nested statement in my code. Now I can't see it - maybe it's awaiting moderator's acknowledge. Does it look better now?
    So treat me nice

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "Widget is disposed" LMDE

    The formatting is better now.

    Is there a forum for the org.eclipse.swt.widgets packages? I haven't seen them discussed on this forum.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Widget is disposed" LMDE

    Well, I googled again and found some eclipse.org forum branch dedicated for SWT only. I've duplicated the topic, and will be waiting for responses both here and there)
    So treat me nice

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: "Widget is disposed" LMDE

    Quote Originally Posted by Scampada View Post
    I've duplicated the topic, and will be waiting for responses both here and there)
    Where? If you cross post on another forum, please leave a link to it so everyone can see the same thing.

  9. #9
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Widget is disposed" LMDE

    Weeell... I haven't duplicated the whole post... I just left there a link to this topic with some brief explanations. I've told them I didn't want to format it twice. Maybe it'd be even better to upload this dumb piece of code to github eh? Heh heh.

    But they haven't acknowledged my topic yet.
    Last edited by Scampada; April 13th, 2013 at 03:41 PM. Reason: good reason
    So treat me nice

Similar Threads

  1. Replies: 1
    Last Post: April 7th, 2013, 03:40 PM
  2. "Program execution skips the "if" statement"!
    By antony1925 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 7th, 2012, 07:15 AM
  3. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  4. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM