Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Example needed using JToggleButton

Posted on 1998-04-08
1
Medium Priority
?
1,719 Views
Last Modified: 2008-02-01
I'm just starting using some of the Swing components and I was wondering how do I use the JToggleButton.  I'd like to have the button "toggle" between two icons.  Can anyone give me an example of how to do this?

Thanks in advance.
0
Comment
Question by:mwalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
mnelson051997 earned 100 total points
ID: 1233996
If you have two GIFs and want one used when the button
is selected and the other used when it is not:

JToggleButton b = new JToggleButton( "text" );
b.setIcon( new ImageIcon( "up.gif" ) );
b.setSelectedIcon( new ImageIcon( "down.gif" ) );

Or, you can pass the "up.gif" icon to the constructor instead
of calling setIcon().
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question