Java, Netbeans: How come the GUI looks different? - java

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.

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.

Eclipse: quick run/preview vs. run main

I am wondering why they 'quick run/preview' displays object different that when you select 'main run' in Eclipse. I personally find that objects look better/neater/more elegant in quick run/preview mode than when I when I run and compile the application via the 'main run' option.
Can anyone tell me there is such a big difference, and what I need to do to actually make my application and its objects look like in 'quick run/preview' mode?
Quick run/preview in Eclipse is used to compile the code and run it more efficiently than normal run. I'm assuming you are referring to this when you are building GUI's?
Anyhow, quick run/preview is just to quickly preview your application regardless of the looks.
I'm assuming you want your GUI to have the Look and Feel of a Windows application rather than the "metal" Java GUI look.
This is done relatively easy as you can both make the "Look and Feel" of your application be based on whatever OS you are running or which one you prefer.
Refer to this simple article here.

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).

How to make Java look like Windows programs?

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.

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...

Categories