Solved

Example needed using JToggleButton

Posted on 1998-04-08
1
1,699 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 119
Impossible to extract MSI from new JAVA releases 2 47
even odd program using while loop 3 27
table example 4 21
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

911 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

23 Experts available now in Live!

Get 1:1 Help Now