3

I am working on a swing application which is currently in English. Now I have to convert it in different languages like Russian, French etc. The problem is that I have given size to components according to English, and I am stuck in handling characters in conversion. For example "Hi" is written in 10 characters in some other language. I cannot change component size. I want to know that what are the ways to do this?

I was looking for something that can change font size to fit the text in the components.

Thanks in advance.

DpkTheJavaCoder
  • 117
  • 1
  • 10
  • *"The problem is that I have given size to components according to English"* - How did you do this? Did you use `setPreferredSize`? – MadProgrammer May 30 '14 at 07:01
  • 2
    Well, congratulations for demonstrating exactly why you shouldn't do this (sorry, I'm not trying to be mean). Are you using layouts or are you using `null` layouts (absolute positioning)? – MadProgrammer May 30 '14 at 07:06
  • You may also find [Internationalization](http://docs.oracle.com/javase/tutorial/i18n/) of use... – MadProgrammer May 30 '14 at 07:07
  • @MadProgrammer- I am using nested layouts. – DpkTheJavaCoder May 30 '14 at 07:09
  • 1
    See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) As an aside, I love seeing it when using preferred sizes comes back to bite the developer in the posterior. It's such a nice change to the constant warnings we issue against that foolish practice. – Andrew Thompson May 30 '14 at 07:09
  • Okay, live just got simpler for you. Instead of using `setPreferredSize`, using things like `Border`s or layouts to make adjustments to the size of components and let the layouts figure it out, allow the flexibility in your design as you do it. As you've discovered, you don't control many of the factors which might change the size of a component on the screen – MadProgrammer May 30 '14 at 07:11

1 Answers1

0

All the commentators already posted the answer. Somehow I'd also like this question to be marked as answered/closed.

So my recommendation is to take a closer look at Layout Managers that calculate a component's screen size on behalf of you. You just specify rules like 'this is left of', or 'that component shall take the main space'. This way it is extremely easy to replace component texts and still have a meaningful screen.

To learn about Layout Managers, follow the fine manual given at https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

Queeg
  • 7,748
  • 1
  • 16
  • 42