Handling characters width in language conversion java swing application - java

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.

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

Related

Dynamical Font-size in TextArea - JavaFX

I am currently trying to get into JavaFx and started writing a program similar to Microsoft Word or Pages on OS X. I had to realize that the TextArea is really limited when it comes to style, so I was wondering if there is a component that is editable (as in you can write on it) and is able to change font size/color dynamically (size and color are defined with a choicebox on the UI.
I read a little but about binding style-types or setting css rules, but as far as I know there is no way to access Java components (choicebox) or even variables from the css style sheet, so it wouldn't be dynamical.
What I mean by dynamically change font size/color:
Type a character into the TextArea.
Double the font size.
Type another character, that now appears twice as big as the first one, that is still displayed in its original size.
I'm having a hard time explaining myself, if you have any questions, please ask and I'll try going into further detail. Thanks
EDIT: Something that might be important is the fact that I am using Scene builder to create my UI.
EDIT 2: Could I cheat my way around it using a Highlighter with the same color as my background?

Is text rendering possible onto 2D images with Javascript/PHP?

I own a sports apparel company and I'm looking to have an applet built that will allow customers to see how their team names will look in certain colors on jerseys. Below you can see the final result of a competitor site's Flash applet where text is rendered on 2D surfaces/images.
My requirements: I need users to be able to set the font, primary text color, outline text color, and text style (arched or straight).
So my question-- Is this sort of text rendering possible with only Javascript/PHP?
If so, what limitations do you for see? I've been told the arching and outline text color may be issues. I've also been told that I may have to upload library files to a server where the actual rendering may take place.
If not, what scripting would you guys recommend? I'm trying to stay away from Flash because it's slow and costly.
I'll be passing this onto our developers so please feel free to be as detailed as possible. I figure'd I'd save them some leg work!
Thank you!
Depending on how complex you want your graphics to be, html5 drawing abilities could be used. Check Raphaël library, for instance, webGL/canvas renderers already have a lot of features in modern browsers.
As of the solution with server rendering, it's also possible with gd2(php), but imho that would be less convenient, at least try something different from php (btw, what's your backend running on?)
Your competitor's solution with java applet honestly seems the easiest, except that it requires jre, which few people are eager to install =)
That's kind-of a high level question, but yes you can definitely use javascript for it.
If there's a problem with getting characters to look right, you can always save each letter as a separate image and have javascript place them next to each other in preview. I'd try to see how close you could get with the existing fonts first.
Layering the text: one color large font, then a different color smaller font will give you the outline effect your looking for.

How to force JTable to NOT invert text in the case it contains arabic characters?

I have the following text:
وزا.word
But when displaying it on my JTable it looks like this:
word.وزا
In every JLabel or TextArea or any other input it does look like the original text:
وزا.word
ONLY on the JTable I am having such problem.
I do not care if it is making sense or not, and yes I know the Arabic Language is written from right to left. My guess is Java is detecting it and automatically inverting it, but I do not want it to.
Note: I have no idea what وزا means, and for practical purposes I don't care. It's also irrelevant for this case wether وزا.word does not make sense and word.وزا does or viceversa.
Note 2: The text, reversed or not is always aligned to the left (as I expect it to).
Thanks in advance.
At a guess, your default Locale is giving the default renderer a ComponentOrientation that is inconsistent with your other settings. You might try creating a custom renderer having the preferred orientation using one of the approaches suggested here.
Addendum: java.text.Bidi supports bidirectional reordering; you may be able to use unicode format control code points, as suggested in this Q&A.

Localization and L&Fs

I thought it would be nice if I gave the user the ability to choose and switch between "themes" (L&Fs). I'd give him a choice between Java metal (default), System default, and maybe a couple more I'll download from the internet...
My application is also bilingual (you can pick between two languaes to be displayed).
However, it's important for my application to be fully translated. I can handle the simple stuff, naming JLabels, JButtons, titles of frames, etc...
But there are also some predefined components whoose string I cannot manage as easely (e.g. JFileChooser). I was told that I could change them using the UIManager, but that their strings are L&F specific.
Now, regardless to how much fun would be translating my application for each and every L&F, I hope there is some centralised way of controlling those strings.
After all, JFileChoose (e.g.) is the same component, no matter the L&F that is used, right?
It prints text on the same parts of itself, no?
So, there should be something I could access that would grant me "master" control over the text that is printed onto the predefined components, I assume...
Any ideas?
not easy job,
have to read Modifying the Look and Feel
most important is Changing the Look and Feel After Startup
have to accept that you have to override value for Keys into UIManeger too, NOTICE about one of Look and Feel
is possible that different L&F have got various Fonts and Colors for concrete JComponents, multiply by Native OS
in some cases is important if you'll to change Color or ColorUIResources (Font or FontUIResources)
JFileChooser is compound JComponents, you can to extract its members,
best place to start could be this idea,
Nimbus Look and Feel lives with own life

What is the best way to display ASCII in a grid with panels using Java?

I don't have much experience in Java, but I am attempt to write a simple rogue-like game to familiarize myself with it, and I am just wondering how I would go about creating an interface like this:
Are there any obvious ways that you would go about something like this? Being new to Java, I really have no idea what the best method would be.
Sorry to be vague!
Thanks
There is no such (simple) component in the JDK - if you don't need color, a JTextArea can be used to display ASCII-Art (after setting a fixed-width font). You will need to take care not to run into characterset issues (if you don't stick to US-ASCII 7-bit).
Writing a component that handles color display (and maybe escape sequences, in essence emulates a console window) wouldn't be too hard, but if you just started with Java it may prove to be an unwelcome challenge.
You could also just write your game in Java and leave displaying the ASCII to the system console (your game would simple output to stdout).
Edit: Color ASCII could be acieved by converting your internal format to (simple) HTML and that HTML could be displayed using a JLabel. Its probably not the most elegant method, but it should be reasonably simple to implement (and with nowadays hardware speed should not be an issue with this approach either). This approach builds on the capability that you can just use JLabel.setText() and pass a string that starts with a HTML tag. The JLabel then interprets the whole text as HTML.
Check out Trystan's Ascii Panel, and his blog and tutorial on making a roguelike here.
Better late than never, right? You may want to check Zircon Project.

Categories

Resources