Java swing windows look and feel

Java: Look and Feel

I am using Netbeans on a Windows machine, what happens is that if I run the main java file the look and feel I get is different than in the case I run the whole program. Meaning if I do this:

But if I do this

I get

Did you see the difference in the look and feel of both the java outputs? Why is it there? I want that when I export it to Jar it should open like the 1st case, nice looking buttons. How?

Update 1: I found the following code in the starting of my main:

So it should set the nimbus look and feel but the problem is that when I open the jar the Nimbus look and feel is not there

Update 2: A look of my Navigator

Update 3: File Structure

6 Answers 6

I am using Netbeans on a Windows machine, what happens is that if I run the main java file the look and feel I get is different than in the case I run the whole program.

When you run a Swing application the default Look and Feel is set to a cross-platform L&F also called Metal. On the other hand when you create a new JFrame from NetBeans New file wizard it also includes a main method just for test purposes, making developers able to «run» the top-level container. Within this main method the Look and Feel is set to Nimbus as you have included in your Update 1.

This is well explained in this Q&A: How can I change the default look and feel of Jframe? (Not theme of Netbeans). As stated there you can modify the template associated to JFrame form to set the L&F you wish. However be aware of this line:

A Java application only needs one main class so this test-only main methods should be deleted when you will deploy your application. [. ] the L&F should be established only once at the start-up, not in every top-level container ( JFrame , JDialog . ).

I just did not understand one thing which test-only main methods do i need to delete and if i delete them how will my prg run properly?

A Java application must have only one main method that inits the execution. The class which has this main method is defined within MANIFEST.MF file when you deploy your JAR. So, having a main method in each top-level container ( JFrame or JDialog ) is not needed and it’s not a good practice.

Читайте также:  Windows 10 1703 или ltsb

However sometimes you don’t want to run the whole application to test how a particular frame/dialog works. That’s why NetBeans includes this main method on JFrame or JDialog creation. But as stated above when you will deploy your JAR you should delete those «extra» main methods.

and yah, in that you have given how to do it when i create new jframes, but i already have 20s of them

A Swing application tipically has a single JFrame and multiple JDialog ‘s. Take a look to this topic for further details: The Use of Multiple JFrames, Good/Bad Practice?

And anyways it is nimbus in there and it is what i want, but that is not what is opening

You just need to programatically set the L&F to Nimbus in your main class (the one that is executed when you run the whole application). You can copy-paste the code you’ve included in your Update 1 there.

Edit 2

When you create a new project in NetBeans it ask you for create a main class too. Let’s say I create a new project called Test , it will ask me for create a main class like this:

This generated Test class will have the main method that triggers the application execution:

Within this main method you have to put the code you’ve included in your Update 1:

Then when you run your application the L&F will be set to Nimbus overriding the default cross-platform L&F. Henceforth all created Swing components will have Nimbus as L&F.

Java Look and Feel (L&F) [closed]

Want to improve this question? Update the question so it’s on-topic for Stack Overflow.

Читайте также:  Ubuntu что такое linux headers

Closed 5 years ago .

I am developing a desktop application with Java Swing for my personal use.I am in need of some beautiful Look and Feel for my application. How can I do it using Java or a 3rd party API?

4 Answers 4

There is a lot of possibilities for LaFs :

Resources :

  • Best Java Swing Look and Feel Themes | Top 10 (A lot of the preview images on this page are now missing)
  • oracle.com — Modifying the Look and Feel
  • wikipedia.org — Pluggable look and feel
  • Java2s.com — Look and feel

You can try L&F which i am developing — WebLaF
It combines three parts required for successful UI development:

  • Cross-platform re-stylable L&F for Swing applications
  • Large set of extended Swing components
  • Various utilities and managers

A few examples showing how some of WebLaF components look like:

Main reason why i have started with a totally new L&F is that most of existing L&F lack flexibility — you cannot re-style them in most cases (you can only change a few colors and turn on/off some UI elements in best case) and/or there are only inconvenient ways to do that. Its even worse when it comes to custom/3rd party components styling — they doesn’t look similar to other components styled by some specific L&F or even totally different — that makes your application look unprofessional and unpleasant.

My goal is to provide a fully customizable L&F with a pack of additional widely-known and useful components (for example: date chooser, tree table, dockable and document panes and lots of other) and additional helpful managers and utilities, which will reduce the amount of code required to quickly integrate WebLaF into your application and help creating awesome UIs using Swing.

Читайте также:  Ubuntu linux с нуля 2 е изд волох сергей васильевич

How to install/configure custom Java Look-And-Feel?

I’m trying to install Sea Glass Look and Feel. I want to install/configure the LaF using a property file, but the tutorial that outlines this process is quite confusing.

That being said, can anyone provide a simple step-by-step guide on installing/configuring a custom LaF using a property file?

3 Answers 3

From their website:

To use the Sea Glass Look and Feel, you must either include our Maven repository in your pom.xml file or download the jar file and include it in your class path. See the downloads page for more details.

To enable the Sea Glass Look and Feel, include the following in your application before creating any controls:

We also support setting the user interface on the command line using the VM option

Here are the steps to install the Sea Glass L&F using the jar file (Note that i use eclipse so the instructions will be in eclipse)

  1. Download the LaF jar file in their Maven repository.
  2. Put the .jar file in a designated folder in your project
  3. Right click your project folder in eclipse the go to ‘Build Path’ then select ‘Configure Build Path’
  4. Under Libraries tab, click ‘Add External Jar’ and go to the folder that contains the jar file

Click Ok then in your code go to your public static void main(String[] args) and copy paste this snippet:

There you go, the L&F is now applied. If you have questions just ask it

Оцените статью