Results 1 to 2 of 2
  1. #1
    daft_punk01 is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Default Display error message for JSlider

    Hi, I have create a Java app using BlueJ, in which you can change the size of a selected shape using a JSlider. One of the shapes to choose from is just a 'point', the size of a pixel, whose size i do not want to be changed.

    I am trying to get an error message to display when the 'point' shape is selected and the user tries to change the size using the JSlider. The code I have got is shown below. The problem I have is that the error message is displayed loads of times in the terminal window if you drag the slider a large amount, it is displayed for each time the slider changes by 1, if that makes sense. Is there any way I can get the error message to display just once no matter how far the slider has moved?

    "
    //When the slider is moved the following method will be called
    public void stateChanged(ChangeEvent e) {

    //Rewrite the label reflecting the new value of the slider
    label.setText("Size: " + adjustsize.getValue() + " pixels");

    //Change size of shape when slider is moved
    adjustsize = (JSlider)e.getSource();

    newSize = adjustsize.getValue();
    aShape.reSize(newSize);

    //If Point shape is selected display error message
    if (aShape == firstPoint) {

    System.out.println("You can't resize a point");

    //Repaint the window to reflect the updates made
    repaint();
    }

    "

    Thanks!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Display error message for JSlider

    Thread moved from New to Java. Also, please go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    Quote Originally Posted by daft_punk01 View Post
    I am trying to get an error message to display when the 'point' shape is selected and the user tries to change the size using the JSlider.
    I would hate to be a user of such an application. The common programming idiom is to disable a GUI control that it isn't right to use.

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

Similar Threads

  1. JTabbedPane to display a message
    By lanmonster in forum AWT / Swing
    Replies: 2
    Last Post: 12-21-2012, 05:37 PM
  2. Replies: 4
    Last Post: 05-15-2011, 04:47 AM
  3. Error message does not display
    By kaga01 in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 12-31-2010, 11:52 AM
  4. how to display only the error message and exit
    By renu in forum New To Java
    Replies: 6
    Last Post: 10-08-2010, 07:50 PM
  5. Display Message Without Throwing Exception
    By kailashchandra in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 09-27-2008, 09:05 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
  •