-2

I have implemented a Seaglass jar theme for my appication, but the theme doesn't work. I have tried add it into different points in my code but nothing I have tried works. Someone please help me.

private void initialize() {


        frame = new JFrame();
        frame.setBounds(100, 100, 577, 443);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        try {
            UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | UnsupportedLookAndFeelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);



        JPanel panel = new JPanel();
        tabbedPane.addTab("New tab", null, panel, null);

        JPanel panel_1 = new JPanel();
        tabbedPane.addTab("New tab", null, panel_1, null);

        JPanel panel_2 = new JPanel();
        tabbedPane.addTab("New tab", null, panel_2, null);

        .. rest of components.

I have already added the JAR as reference in my project, added it to the build path.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Volazh
  • 126
  • 2
  • 13

1 Answers1

1

In my opinion you should have your L&F code as the first item of business within the application's starting main() method. This should be in place before you start applying components to your application. You also need to add the seaglasslookandfeel-0.2.1.jar file (for JRE 1.8 and later) into the Class-path for your project.

In Eclipse:

  1. Put the seaglasslookandfeel-0.2.1.jar file in a designated folder in your project;
  2. Right Click your project folder in Eclipse then go to Build Path then select Configure Build Path;
  3. Under Libraries tab, click Add External Jar and go to the folder that contains the jar file;
  4. Click the OK button then in your code, go to your public static void main(String[] args) method and copy paste this code at the very beginning of it:

    try {
        UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
    } 
    catch (ClassNotFoundException | 
           InstantiationException | 
           IllegalAccessException | 
           javax.swing.UnsupportedLookAndFeelException ex) { 
        ex.printStackTrace(); 
    }
    

In NetBeans (8.0+):

  1. Put the seaglasslookandfeel-0.2.1.jar file in a designated folder in your project;
  2. Right Click your project folder in the NetBean's Projects pane then select the Properties menu item (at bottom of menu);
  3. In the Project Properties dialog window now displayed select Libraries from the Categories pane;
  4. Now select the Compile tab then select the Add JAR/Folder button and go to the folder that contains the jar file and select it then select the OK button;
  5. The seaglasslookandfeel-0.2.1.jar JAR file should now be displayed within the Compile-time Libraries pane. Click the OK button within the Project Properties dialog;
  6. In your code, go to your public static void main(String[] args) method and copy paste this code at the very beginning of it:

    try {
        UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
    } 
    catch (ClassNotFoundException | 
           InstantiationException | 
           IllegalAccessException | 
           javax.swing.UnsupportedLookAndFeelException ex) { 
        ex.printStackTrace(); 
    }
    

Your main() method should look something like this:

public static void main(String args[]) {
    try {
        UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
    } 
    catch (ClassNotFoundException | 
           InstantiationException | 
           IllegalAccessException | 
           javax.swing.UnsupportedLookAndFeelException ex) { 
        ex.printStackTrace(); 
    }

    // The rest of your main() method code here....
}

The SeaGlass Look&Feel should work now.

DevilsHnd - 退職した
  • 8,739
  • 2
  • 19
  • 22