Solved

Example needed using JToggleButton

Posted on 1998-04-08
1
1,697 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
1 Comment
 
LVL 1

Accepted Solution

by:
mnelson051997 earned 50 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
json format text only 4 64
mapShare challenge 13 66
eclipse formatting 6 38
ArrayIndexOutOfBoundException 9 29
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now