Results 1 to 7 of 7
Thread: Look and Feel doesn't work.
- 12-24-2012, 02:17 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 15
- Rep Power
- 0
Look and Feel doesn't work.
Okay, i'm currently programming a java game and atm i am making a Game Launcher for it. I'm trying to make the Gui look better cause atm it's just ugly. Here's the code that matters.
Now i have already been through this issue before. It has something to do with the setLayout(null); part.Java Code:import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import javax.swing.*; public class main extends JFrame{ main(){ //Removed this code as it doesn't matter. It's jsut the placement of all of the buttons and whatnot. setLayout(null); } public static void main(String args[]){ main gui = new main(); try{ UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch(Exception e){ System.out.println("Nimbus isn't available"); } gui.setTitle("Launcher"); gui.setVisible(true); gui.setLocationRelativeTo(null); gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gui.setSize(600, 400); gui.setResizable(false); }
There is some code i used to have that somehow fixed this. it was something like "UIManager.updatetool" or something like that... Any help?
Here's an image of my current launcher.

As you can see, the JButtons and JTextFields are NOT using the Nimbus layout.
-
Re: Look and Feel doesn't work.
I am no expert on L&F, but I believe that you must set it *before* you create any GUI components. So consider swapping the two lines indicated below.
Also, you really should avoid all use of the null layout.Java Code:public static void main(String args[]){ // swap the line of code below main gui = new main(); // with this block of code try{ UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (....) { .... }
- 12-24-2012, 03:29 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 15
- Rep Power
- 0
-
Re: Look and Feel doesn't work.
So you have tried calling the set look and feel as the very first part of the main method? And this didn't work? If so, please double check.
For many reasons including..., and why not use setLayout null?- The GUI will look better on multiple platforms
- Decrease the risk of layout bugs
- Make your GUI *much* easier to maintain and upgrade.
- 12-24-2012, 03:40 AM #5
Member
- Join Date
- Nov 2012
- Posts
- 15
- Rep Power
- 0
Re: Look and Feel doesn't work.
Okay i know for sure that i've tried that before, but i tried it again just to make sure and for some reason it works now. Thanks =D
- 12-31-2012, 12:40 PM #6
Member
- Join Date
- Sep 2012
- Location
- Guntur, India
- Posts
- 27
- Rep Power
- 0
Re: Look and Feel doesn't work.
Try using.
This will definitely work if you have Java 1.7 or higher.UIManager.setLookAndFeel("javax.swing.plaf.nimbus. NimbusLookAndFeel");
- 12-31-2012, 04:21 PM #7
Re: Look and Feel doesn't work.
The better, version-independent way of attempting to use the Nimbus LaF is explained in the Tutorial: Nimbus Look and Feel (The Java Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Jar doesn't work
By mad72584 in forum New To JavaReplies: 35Last Post: 08-07-2011, 05:22 PM -
How to work Nimbus Look & feel in java
By justbeller in forum AWT / SwingReplies: 5Last Post: 01-18-2011, 01:08 PM -
How to work Nimbus Look & feel in java
By justbeller in forum Java 2DReplies: 1Last Post: 01-18-2011, 06:59 AM -
Doesn't anyone here know how to help? I feel like I wanna hang myself
By I Want To Kill Java in forum Advanced JavaReplies: 25Last Post: 12-29-2010, 10:29 AM -
Why doesn't this work?
By Corder10 in forum New To JavaReplies: 1Last Post: 07-04-2009, 10:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks