This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

changing font seems to change the whole area of my JTextArea  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find the relationship between preferred size of JComponents and restrictions imposed upon them by their containers and their containers layout managers quite confusing, but I am starting to get the hang of when it is appropriate to use different managers to arrange things as desired. But now for some reason, changing font size of the font in JTextArea changes the whole size of the area, even when there is no text in it!? can't figure out the reason for this.. I have the following:

In case it is at all relevant, I put the textArea into a JScrollPane, added the JScrollPane to a JPanel and then added the JPanel to the content pane of the JFrame (to the CENTER). Layout managers are their defaults (BL for JFrame, FL for JPanel).

Thanks for any help
 
Saloon Keeper
Posts: 4753
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create your JPanel set its size. Meaning
see if that helps
 
Marius Semeon
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but that didn't seem to work. The font size of the JTextArea still seems to dictate how big the textarea is
 
Carey Brown
Saloon Keeper
Posts: 4753
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, try that on your JTextArea instead.
 
Carey Brown
Saloon Keeper
Posts: 4753
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the part of your code where you are creating the JPanel, JScrollPanel, and JTextArea?
 
Rancher
Posts: 2941
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But now for some reason, changing font size of the font in JTextArea changes the whole size of the area, even when there is no text in it!? can't figure out the reason for this



That is correct. The preferred size calculation is based on the font size and the number of rows and columns you want.

So when you use:



You are saying that 25 rows and 45 columns of the text area should be visible on the screen (before scrolling).

So with a larger Font the text area will be a larger size.
 
Marius Semeon
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Can you post the part of your code where you are creating the JPanel, JScrollPanel, and JTextArea?



Yes, here it is. Sorry late reply i've been very ill. I tried setting preferred/max/minSize on the JTextArea and it didn't effect it, but I guess it's because it was inside a JScrollPane so it's the outer container that dictates it. When I set the sizes on the JScrollPane it all worked fine. Sorry this is a really basic question, i just fine the whole layout aspect and sizing confusing in java.

 
Marshal
Posts: 60124
188
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a long time since I tried it, but it used to be possible to use HTML tags on a Component; I think a JLabel. Since the tags can include font size, that might allow you different font sizes for the same size component. Of course, you can't allow the user to enter text on a JLabel as you can on a text component. As RC suggests, you may be stuck with different sizes for different fonts.
 
Author
Ranch Hand
Posts: 964
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Marius Semeon wrote:I tried setting preferred/max/minSize on the JTextArea and it didn't effect it, but I guess it's because it was inside a JScrollPane so it's the outer container that dictates it. When I set the sizes on the JScrollPane it all worked fine.



What a JScrollPane does is allow you to put a large object inside something (the JScrollPane's JViewport) that is (or at least can be) smaller in size. So the JTextArea itself remains unconstrained, and it's not quite correct to say that the JScrollPane is constraining it.

[note: No big deal, but Dimenension should be corrected to Dimension in your code.]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!