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

    Default Progress Bar with Cancel Button using SWT implementation issue

    Dear Members,

    I am new to java. I have to create progress bar and cancel button on UI. I am using SWT to create the progress bar and button both.
    The functionality is that when one process is going on progress bar status will keep changing and if Cancel button is clicked, the process will stop and control will take to different screen.
    Here is the piece of code written by me:

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Button;

    private Button cancel = null;
    private ProgressBar progressBar = null;
    progressBar = new ProgressBar(toplayer, SWT.NONE);
    cancelProgress = new Button(layer, SWT.NONE);

    progressBar.setBackground(new Color(null, 255, 255, 255)); // White
    progressBar.setLayoutData(getFormdata(57, 05, 95, 65));
    progressBar.setBounds(0, 0, 100, 100);

    cancelProgress.setText("Cancel");
    cancelProgress.setBackground(new Color(null, 240, 200, 120));

    cancelProgress.setFont(getFont(12, SWT.BOLD));
    cancelProgress.setLayoutData(getFormdata(83, 15, 89, 96));

    cancelProgress.addMouseListener(new MouseListener() {

    @Override
    public void mouseUp(MouseEvent arg0) {

    }

    @Override
    public void mouseDown(MouseEvent arg0) {
    cancelProgressClicked = true;

    }

    @Override
    public void mouseDoubleClick(MouseEvent arg0) {

    }
    });

    But I am facing one problem. On the screen "Cancel" button doesn't recognize any event. While Progress Bar is working fine. Even when i take cursor on "Cancel" button no action is seen and also no action on click.

    Could anybody please solve this issue? Looks something silly i am doing but this is very critical. Thanks in advance.

    With regards,
    Anoop.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    Why are you using SWT instead of Swing? Please include a Short, Self Contained, Correct Example that demonstrates your problem. From the code above it is not clear where you add the event listener for your button.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

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

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    Quote Originally Posted by jim829 View Post
    From the code above it is not clear where you add the event listener for your button.
    Huh?

    Java Code:
    cancelProgress.addMouseListener(new MouseListener() {
    // yada yada
    }
    Rather clear. I don't know any SWT but I find it odd that a mouse click listener would be used. This example shows something very different:

    SWT Button Action : Button**SWT JFace Eclipse**Java
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    aks_anoop is offline Member
    Join Date
    Feb 2015
    Posts
    5
    Rep Power
    0

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    Hi Jim,

    I have to use SWT only.
    Progress bar and cancel button implementedon the same page only. Here is the code written for "Cancel" listener

    cancelProgress.addMouseListener(new MouseListener() {

    @Override
    public void mouseUp(MouseEvent arg0) {
    }
    @Override
    public void mouseDown(MouseEvent arg0) {
    cancelProgressClicked = true;
    }
    @Override
    public void mouseDoubleClick(MouseEvent arg0) {
    }
    });

    CancelProgress is the button , when clicked takes to a different page. But "Cancel" button is not responding to any event.

    Please help.

    Thanks & regards,
    Anoop.

  5. #5
    aks_anoop is offline Member
    Join Date
    Feb 2015
    Posts
    5
    Rep Power
    0

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    Hi,

    As I have to use SWT only and I can't use shell, please let me know any solution in the code given by me. Please help.

    Thanks & regards,
    Anoop.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    Quote Originally Posted by gimbal2 View Post
    Huh?

    Java Code:
    cancelProgress.addMouseListener(new MouseListener() {
    // yada yada
    }
    Rather clear. I don't know any SWT but I find it odd that a mouse click listener would be used.
    Well, I clearly missed that. I was focused on the mouseListener part. Rather cumbersome I would think using mouse movements to detect button activity.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    Quote Originally Posted by aks_anoop View Post
    Hi,

    As I have to use SWT only and I can't use shell, please let me know any solution in the code given by me. Please help.

    Thanks & regards,
    Anoop.
    Look at the link gimbal supplied and use a regular Listener, rather than a mouse listener.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    Moved from AWT/Swing. Next time, please take the trouble to post in the correct section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    aks_anoop is offline Member
    Join Date
    Feb 2015
    Posts
    5
    Rep Power
    0

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    Quote Originally Posted by jim829 View Post
    Well, I clearly missed that. I was focused on the mouseListener part. Rather cumbersome I would think using mouse movements to detect button activity.

    Regards,
    Jim
    Hi Jim,

    Could you please let me know how to use mouse movements to solve above issue. I tried but it didn't resolve the issue.
    Please help as this is very critical issue for me. You can suggest any other solution also keeping in my that i have to use SWT only.

    Thanks & regards,
    Anoop.

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

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    So did you ever take a look at the link I posted at all?

    PS: if it is really so critical that you can only wait more than a week before you post a reply, why not try the actual Eclipse SWT forum to reach a broader audience?

    http://eclipse.org/forums/index.php?t=thread&frm_id=100


    Around here we mostly use the standardized Swing/JavaFX so you're not really reaching anyone that has been where you are right now.
    Last edited by gimbal2; 02-16-2015 at 03:09 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    aks_anoop is offline Member
    Join Date
    Feb 2015
    Posts
    5
    Rep Power
    0

    Default Re: Progress Bar with Cancel Button using SWT implementation issue

    Quote Originally Posted by gimbal2 View Post
    So did you ever take a look at the link I posted at all?

    PS: if it is really so critical that you can only wait more than a week before you post a reply, why not try the actual Eclipse SWT forum to reach a broader audience?

    Eclipse Community Forums: Standard Widget Toolkit (SWT)


    Around here we mostly use the standardized Swing/JavaFX so you're not really reaching anyone that has been where you are right now.
    Hi Gimbal2,

    Sorry for the delay in response. Actually, I had so many things to develop and fix that is why i kept this issue aside and focussed on other issue which i could solve easily. That is why it took time to respond. But this is crucial implementation to complete the project. As you directed I have posted in the mentioned forum also.
    Please let me know if you have any solution. I am really sorry once again for the delay in response.

    Thanks & regards,
    Anoop.

Similar Threads

  1. JoptionPane Cancel and 'X' button confusion
    By IanKW in forum New To Java
    Replies: 15
    Last Post: 09-30-2014, 09:41 AM
  2. Replies: 1
    Last Post: 12-14-2011, 10:23 PM
  3. Cancel button ? In java
    By smasm in forum New To Java
    Replies: 21
    Last Post: 10-01-2011, 06:24 AM
  4. Cancel button for exiting app
    By phearless in forum AWT / Swing
    Replies: 1
    Last Post: 01-13-2011, 07:20 PM
  5. Struts 2 cancel button
    By kirtichopra2003 in forum Advanced Java
    Replies: 0
    Last Post: 09-29-2009, 03:40 PM

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
  •