Results 1 to 8 of 8
  1. #1
    jjlin12 is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default Changing Image Icon of a JButton at run time, NOT state dependent

    Hi all,

    I need to change the Image Icon of a JButton. I know there are built in methods to change the Icon when it is in a certain state (i.e. pressed, scrolled over, etc). But I need it to change when another method tells it to.

    Basically an action happens, a method decides what to change the JButton's Image Icon to (depending on what happens in the action), then it changes it. That's what I want in theory, anyways.

    Are there any simple solutions to this?

    Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,926
    Rep Power
    8

    Default

    Did you check the API or the tutorials?

    Hint: Sounds like you're looking for a method that sets the icon, neh?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Have you read the API doc for the JButton class? Do any of the methods look like they would do what you want them to do? Have you written a small program to test those methods to see if the work like you want?

    If you are having problems with your small test program code, post it here with your questions.

  4. #4
    jjlin12 is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    Did you check the API or the tutorials?

    Hint: Sounds like you're looking for a method that sets the icon, neh?
    secticon()

    Sets the button's default icon. This icon is also used as the "pressed" and "disabled" icon if there is no explicitly set pressed icon.

    Parameters:
    defaultIcon - the icon used as the default image
    See Also:
    getIcon(), setPressedIcon(javax.swing.Icon)

    --------------------------------------------------------------------------------

    I don't want to set a default image. If anything that's the opposite of what I need to do.

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,926
    Rep Power
    8

    Default

    Quote Originally Posted by jjlin12 View Post
    I don't want to set a default image. If anything that's the opposite of what I need to do.
    Are you sure? I might be misunderstanding your requirements, but have you followed Norm's advice and actually tried any of this in a small example program?

    PS- Secticon sounds like an awesome transformer.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Have you tried it to see what happens?
    The class has methods you can use to work with its icons. If what you want to do is not there, then it's not there.

  7. #7
    jjlin12 is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Have you tried it to see what happens?
    The class has methods you can use to work with its icons. If what you want to do is not there, then it's not there.
    I'll try it, although according to its description it doesn't sound like this is its inteded use.

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,926
    Rep Power
    8

    Default

    Quote Originally Posted by jjlin12 View Post
    I'll try it, although according to its description it doesn't sound like this is its inteded use.
    I disagree. I believe you are misinterpreting the description.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. changing JButton image upon clicking
    By Logical in forum AWT / Swing
    Replies: 2
    Last Post: 12-21-2010, 02:53 AM
  2. Changing Java Icon
    By Adam Cruge in forum Java 2D
    Replies: 20
    Last Post: 07-21-2009, 02:32 AM
  3. Changing colors of an image in real time
    By chale in forum CLDC and MIDP
    Replies: 0
    Last Post: 05-06-2009, 03:04 PM
  4. Time constraints on object state
    By Flipke in forum New To Java
    Replies: 4
    Last Post: 04-11-2009, 06:12 PM
  5. Changing icon of JOptionPane
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-21-2007, 07:01 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
  •