JavaFx application font on different os - java

I've finished my JavaFx application and compiled the program. However, my application uses a font from "Apple". When I opened the application on a different OS like my Windows 10 PC, the font was completely different and the things such as buttons and text labels were too long that is created ellipsis ("..."). Is there a way I can transfer fonts over, or force the application to only run under a certain font?
Thanks in advance.

How about setting your controls (buttons,labels etc) to use a safe font family (as described by ampsoft.net and referenced in this question) in your CSS file?
For example:
.button{
-fx-font-family:'serif';
}
.label{
-fx-font-family:'serif';
}

Related

How to change font size on a desktop Java application?

I wrote a program, exported it as ".jar" and ran it on a computer other than my developer desktop PC. The problem arose that the entire JFrame on the laptop was smaller and therefore certain texts were replaced with "..." because the component was too small to display it completely. Now the question arises is there the possibility to change my text size dynamically that it is always getting displayed completely?
Edit 1:
My problem is that I first have to get the font size at which my text is replaced by "...".
|that is the code|
|that is how the gui should look (It looks like this on my desktop pc)|
|that is how the gui looks on my laptop|
I have not really a solution to the problem but I know what was the fault. My windows was scaled to 125% so some text dissapeared...

Making new font available to the JVM

I have a Scala/Java service running on a JVM. This is a graphical application that renders images.
While it's running, I want to add fonts it can use. So I install the fonts, and all things work great. EXCEPT that I must restart the service in order for the fonts to work.
So, how to make the JVM load the new fonts I've installed without restarting it?
I can only guess at what you need and give basic examples, before we can help much more you will need to give us more details or an example of how you are currently trying to install/load the font, and how you apply it to your rendered images.
Are you installing the font every time your application runs? This should not be the case, you can do everything from within Java.
Java loads most fonts by itself, so if you are using an already installed/existing font then you can load and use it the normal way, like this:
Font font = new Font("Dialog", Font.PLAIN, 12);
your2Dgraphics.setFont(font);
your2Dgraphics.drawString(String str, int x, int y)
If you want to load the fonts manually from within your program or another directory then you should be doing it like this:
GraphicsEnvironment graphicsEnviro = GraphicsEnvironment.getLocalGraphicsEnvironment();
graphicsEnviro.registerFont(Font.TRUETYPE_FONT, new File("myFontToLoad.ttf"));
Once when you start the program load the font into memory, so you do not have to load it from file every time you need to use it.
I recommend a quick read about fonts in Java, take a look here:
https://docs.oracle.com/javase/tutorial/2d/text/fonts.html

Font glyph fallthrough in Java

Does anyone know of an existing solution for font glyph fallthrough in Java? For example, our designers have decided that Calibri is the font that mostly fits our needs, but if I specify Calibri, it can naturally not render characters that do not have a matching glyph in that font. In that case, I would need it to fall through to a second specified font, and if all else fails - use one of Java's logical fonts.
Has anyone come up with a solution for this, which can be plugged into existing Swing components without having to write custom Swing components for the entire project?
This is a very old project already, and building custom graphical components is not a feasible solution.
This isn't a code-based solution and probably won't be of much help, since it requires each user to install a file locally, but just in case...
You can add fallback fonts in a special directory within the JRE installation. From the Java documentation:
Users can add a physical font as a fallback font to logical fonts used in Java 2D rendering by installing it in the lib/fonts/fallback directory within the JRE.

Multi language software to run on two platforms

i had developed application in ubuntu using eclipse platform .i used our local language as displaying in gui forms.i used JLabel b = new JLabel("fonts of local lanuage(gujarati)");
i works properly in ubuntu but when i run this on windows it wont show properly means it displays like [][][][][][][].how to correct it.plz help me.
That may refer to Font. make sure you have fonts available in windows.
This is a link to a unicode to un-unicode converter. it may be useful
Yep the problem that you are facing is the font that is why when you run on windows it comes up like this
[][][][][][][]. The simplest solution to this is use a font native to windows such as Arial or Times New Roman.

Java Swing positioning elements differently in different operating systems

I have written a Java Desktop Application that runs in Windows, Mac OS X, Ubuntu and Open Suse. I am having issues with is positioning thing differently in Linux.
I developed the application with NetBeans using the designer, it looks as I would expect in Windows and Mac OS X, but in the Linux distros certain label controls have shifted into different positions.
Is there a common reason for this?
Perhaps Linux uses a different font. One where letters have a different width.
You could try to explicitely set a specific font for your Look&Feel. It should be a font which is installed on all of your target platforms.
The most probable thing is that you use different Look and Feel for every platform. If you're developing in Windows you do layouts to fit for Window style only. But Linux has different L&F with different margins and font for GUI components. Metal style (basic for Linux) and its descendants (Nimbus and GTK+) have larger default system font and heights for components. I think, that must be a reason why you have shiftings.
The way to fix that is to check program looking in both platforms. I'd suggest to develop in Metal style because Windows has smaller fonts, as result, everything which fits in Metal will fit in Windows.
I'm assuming you developed the thing on Windows or Mac, that's why it looks "as expected". Can you compiling/running the code in your IDE on Linux and see how it looks?
My guess is that one of the implementations of the containers is flawed. I saw this sometimes when I did cross-development and mostly did trial-and-error modifications to fix it (by changing to use other classes). It also helped to have one developer working in Windows and another in Linux, so that we would easily spot and fix problem areas.
I changed the Layout style from 'Free Design' to 'Absolute'

Categories