Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How to use JSlider to adjust Text in a JPanel

 
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

 
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
 
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic