Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link a scrollbar to a text value

Status
Not open for further replies.

Bravogolf

Programmer
Nov 29, 2002
204
GB
Hi all.

I'm still learning Java so bear with me! Basically, I have created a java application with three scrollbars and want to be be able to link the scrollbars to a text value so that as I increase scrollbar A from the beginning to the end, the text box of scrollbar A will increase in value from 0 up to 255 (and display that value in the text box). Can anyone help me?
 
Sorry, I mean the ScrollBar. Thanks for the link :) Any ideas?
 
You need to add a listener to your Scrollbar. Here is a simple example to get you started :

Code:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;



class Test {
	class AdjustmentListenerImpl implements AdjustmentListener {
		public void adjustmentValueChanged(AdjustmentEvent e) {
			System.out.println("Value changed to : " +e.getValue());
		}
	}

	public void doIt() {
		JFrame f = new JFrame();
		f.setSize(400, 400);
		Scrollbar  ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 10, 0, 255);
		AdjustmentListenerImpl al = new AdjustmentListenerImpl();
		ranger.addAdjustmentListener(al);
		Panel p = new Panel();
		p.add(ranger);
 		f.getContentPane().add(p);
 		f.setVisible(true);
	}

 	public static void main(String args[]) throws Exception {
		new Test().doIt();
	}
}

Click here to learn Ways to help with Tsunami Relief
--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top