Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use JSlider to adjust Text in a JPanel  RSS feed

 
Louie Bagz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys,

maybe you can help me on this...

my application uses a JSlider... I want to be able to adjust the size of the text to give a zooming in/out effect.

I have the initial code... but the JSlider doesnt work...

Here is the link of the intended output...

http://www.geocities.com/louiebagz/files/jslider.jpg

 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Louie, and welcome to JavaRanch!

You just need to tie the JSlider value to a font size, and reset the font on your component when it changes. For instance, this ChangeEvent on a JSlider gets its value, and uses it to set the Font size:

Just set the min and max values of the slider to your min and max font sizes.

Hope that helps!

Darrin
 
Louie Bagz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Darrin,

thanks for the inputs... for newbies like me, I really appreciate that...

But I have one thing more to ask... When I run the code, the initial size of the text displayed is not the same as what I declared.

Please provide feedback. Thanks!

Here is the code...

 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,

Even JPanels have a default Font associated, you just need to set the Font when you first create the TextSpace(). Example:


Good luck!
 
Louie Bagz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Darrin,

Thank you so much! That's just what I need...

Louie
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!