• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

How to use JSlider to adjust Text in a JPanel

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darrin,

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

Louie
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic