Results 1 to 7 of 7
  1. #1
    Pinky4Free is offline Member
    Join Date
    Nov 2012
    Posts
    15
    Rep Power
    0

    Default 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.
    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);
    	}
    Now i have already been through this issue before. It has something to do with the setLayout(null); part.
    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.
    Look and Feel doesn't work.-help1.png
    As you can see, the JButtons and JTextFields are NOT using the Nimbus layout.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

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

    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 (....) {
               ....
            }
    Also, you really should avoid all use of the null layout.

  3. #3
    Pinky4Free is offline Member
    Join Date
    Nov 2012
    Posts
    15
    Rep Power
    0

    Default Re: Look and Feel doesn't work.

    Quote Originally Posted by Fubarable View Post
    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.

    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 (....) {
               ....
            }
    Also, you really should avoid all use of the null layout.
    I already tried placing it there, and why not use setLayout null?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Look and Feel doesn't work.

    Quote Originally Posted by Pinky4Free View Post
    I already tried placing it there...
    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.

    ..., and why not use setLayout null?
    For many reasons including
    • The GUI will look better on multiple platforms
    • Decrease the risk of layout bugs
    • Make your GUI *much* easier to maintain and upgrade.

  5. #5
    Pinky4Free is offline Member
    Join Date
    Nov 2012
    Posts
    15
    Rep Power
    0

    Default 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

  6. #6
    gowthamgutha is offline Member
    Join Date
    Sep 2012
    Location
    Guntur, India
    Posts
    27
    Rep Power
    0

    Default Re: Look and Feel doesn't work.

    Try using.

    UIManager.setLookAndFeel("javax.swing.plaf.nimbus. NimbusLookAndFeel");
    This will definitely work if you have Java 1.7 or higher.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

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

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Jar doesn't work
    By mad72584 in forum New To Java
    Replies: 35
    Last Post: 08-07-2011, 05:22 PM
  2. How to work Nimbus Look & feel in java
    By justbeller in forum AWT / Swing
    Replies: 5
    Last Post: 01-18-2011, 01:08 PM
  3. How to work Nimbus Look & feel in java
    By justbeller in forum Java 2D
    Replies: 1
    Last Post: 01-18-2011, 06:59 AM
  4. Doesn't anyone here know how to help? I feel like I wanna hang myself
    By I Want To Kill Java in forum Advanced Java
    Replies: 25
    Last Post: 12-29-2010, 10:29 AM
  5. Why doesn't this work?
    By Corder10 in forum New To Java
    Replies: 1
    Last Post: 07-04-2009, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •