How to make Java look like Windows programs? - java

Is there a way (using Java) to make the GUIs that you create look like normal Windows programs? I don't like the look and feel of the Java buttons and scrollers and stuff... It can use those if it's running on Mac or Linux, but I'd like it to inherit the buttons and stuff from Windows. Any suggestions?

You can set the look and feel of any Swing program to the native operating system's with one call.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
The Windows PLAF can be seen in the Nested Layout Example.

Related

Corrupted java swing component

I'm working on a Java Swing project,
I have an issue with some component while running projects vs running the interface here's some screen shoot :
This look when I run only the jFrame
This is when I run A Frame that lead to this
and this when i run the full project
I want to know why this look difference and how to resolve it.
I'm Using netbeans 12.2 with jdk 15.0.2 on a windows 64 bit machine
Java Swing by default uses native GUI components. The upside of this is that when done correctly, your Java application will have a Windows style on Windows and a Linux on Linux etc. To get a fixed style, you can set the Java Look And Feel to a LAF that is always available, such as the built-in METAL LAF. This page contains much more specifics on Java Look And Feels, how to set them and even how to create your own if you wish.

java L&F to obtain modern "wpf" look

Recently I found some absolutely beautiful applications made using WPF.
I'd really like to add this lovely look to my java applications.
Do you know if there are look and feels which make it possible?
First of all think what are the key concepts of the new metro-UI ?
Its flat and simple
1) use metro studio 2 to create icons for the project, use flat borders always
2) either create a full L&F or simply create small custom components ? or use Java FX (http://pixelduke.wordpress.com/2012/10/23/jmetro-windows-8-controls-on-java/ , http://pixelduke.wordpress.com/category/javafx/page/3/)
I was able to come little bit close to metro like text-buttons and background repeat panels, you might also want to see my repo here https://github.com/JaDogg/BhathiGUI
above image is for my near metro custom controls
NOTE : this will not create an actual metro app just one that looks like it
Update
Here is a screenshot of JavaFX application built using Undecorator and JMetro (JavaFX8)
Java was always stingy on new L&F. So new WPF style (developed for Windows 8 apps) is not available yet and i doubt it will be anytime soon.
The latest L&F released and provided together with Java SE was NimbusLookAndFeel. It is based on SynthLookAndFeel, which supposed to be a base for any custom L&F from now on.
There are also native L&Fs with:
Windows 2000 and Vista/7 styles (WindowsLookAndFeel)
GTK style (GTKLookAndFeel)
Mac OS style (AquaLookAndFeel)
There are also some good commercial L&Fs:
Java Look and Feel (L&F)
So if you really want to have such L&F - you will have to modify some existing L&F so it matches WPF styling or wait for a miracle (that someone will release such L&F).

Swing and GTK font

I have write a little GUI with java Swing. But i have some little problems with the default look and feel using com.sun.java.swing.plaf.gtk.GTKLookAndFeel
As you can see the menus and the buttons doesn't have the same font of the other application in my Desktop (In the picture Eclipse and Nautilus), I'm using GTK on Gnome2.
Meanwhile using the relative look and feel on windows there are not differences:
The font look identical.
How is it possible this? Which parameters can I modify to edit the font look on GTK?
You should let the System decide which L&F to use
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
In your above image you are using Ubuntu with Unity (I guess?), but Unity does not use GTK but Nux.
Another way to create a native Look and Feel is the using the SWT (Standard Widget Toolkit) that provides you with system dependent libraries for Windows, Linux and OSX, so that the graphical elements in your program use the actual native elements from those systems. But I have to warn you, it may not be that easy (and sometimes even weird and annoying :) ) to use, because you cannot use any Swing components. So maybe that's not worth the trouble – it's for you to decide.
Consider setting defaults for the fonts on components after setting your look and feel.
UIManager.put("Menu.font", new FontUIResource(your_desired_font));
UIManager.put("Button.font", new FontUIResource(your_desired_font));
Windows L&F is using by default new Font("Tahoma", Font.PLAIN, 11);
For GTK, set the font standard by UIManager.getLookAndFeelDefaults() does not work... then I found a hack via reflection that works, you can find it here in response:
https://stackoverflow.com/a/31345102/3757320

How to make your desktop Java app looks like Open Office or Eclipse etc.?

How to make your desktop Java app looks like Open Office or Eclipse etc ?
Installation process looks like any Windpws app. installation. There is no Java logo on the to on a app window. You run it by .exe file. How it is done? Is this jar->exe conversion?
Is there any free tool to do that?
For the native look, you can obviously go the SWT way, like Eclipse does, however it's a painful one. You could/should prefer the Swing look'n'feel, by using, as an example, the Substance Look'n'Feel.
For the installation part, you can use
InstallAnywhere
IzPack
For the exe wrapper, you can use
Launch4J
JSmooth
or others ...
However, I think that, by doing so, you're doing it wrong.
indeed, instead of the classical download/install step, which is cumbersome, you can go the Java Web Start way : user only has to click one webpage link to install application to its machine (with an update mechanism directly integrated in), an install that go as far as potentially including desktop and start menu shortcuts, and an element in the Windows install panel to remove installed software.
I tried Jar2Exe, and JSmooth, they both produce exe files from jar archives.
The question is a little unclear, but I think that what you're after is making your java app behave like a native app (stuff like running it when an icon is double-clicked, etc...). There is an excellent tutorial on this here.
Note that, for the graphic part, Eclipse uses a library called SWT, which is a set of widgets that feel and behave in a different way that Java Swing or AWT.
Anyway, if you go the normal Java (Swing) way, the Java logo on the top of an app window is setIconImage() method in JFrame components.
Riduidel already told you about .exe wrappers and installers you can use. For the installer, I also suggest you to consider Java Web Start instead of a normal Windows installer.
I think it uses LookAndFeel, I let you read: http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e){}
EDIT: I didn't read the entire question ^^' Maybe it will be useful to someone...

Java, Netbeans: How come the GUI looks different?

I'm a Java/Netbeans newbie learning how to make a GUI.
I was following this tutorial, and I noticed that the "finished" product (first picture in that link) doesn't look like the GUI built through the steps.
Why is that? I mean, when I click on the preview button, the GUI looks native (nice) as well. It's just when it's deployed that it looks all...mmm...bad. lol.
Is there a way to make the finished GUI looks native? Is it Netbeans settings or Java settings?
Note: I'm developing this on Windows.
Use the following code to force swing to select the "system" look and feel:
String laf = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(laf);
The default "Look and Feel" is metal-like, which is good and nice for cross-platform applications.
JDK has 4 built-in "look and feel" ('til now), which are:
com.sun.java.swing.plaf.gtk.GTKLookAndFeel
javax.swing.plaf.metal.MetalLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
you can try any of these "look and feel"s in 1 line, example code:
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
NOTE: invoke/call this method of changing the "look and feel" before any GUI implementation, or it may throw some exception
This is referred to as the "look and feel". You can use various look and feel either when launching your app or programaticaly. See this Sun tutorial for more info.

Categories