7 Replies - 397 Views - Last Post: 28 January 2014 - 11:26 PM Rate Topic: -----

#1 incredibleX  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 01-November 13

Java LookandFeels

Posted 02 November 2013 - 03:28 PM

i have to create a selection panel between looks and feels.
when one radio button is clicked the whole frame should turn to nimbus and on the click on other button nimbus turns to windows clasic and so on.

The thing i only know is that if we place the following code in mainit will turn every thing to nimbus.
what to do for other feels.
how can i make it out of main in some other method, sothat i may call it when needed?

	try {
	         for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
	             if ("Nimbus".equals(info.getName())) {
	                 javax.swing.UIManager.setLookAndFeel(info.getClassName());
	                 break;
	             }
	         }
	     } catch (ClassNotFoundException ex) {
	         java.util.logging.Logger.getLogger(mainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	     } catch (InstantiationException ex) {
	         java.util.logging.Logger.getLogger(mainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	     } catch (IllegalAccessException ex) {
	         java.util.logging.Logger.getLogger(mainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	     } catch (javax.swing.UnsupportedLookAndFeelException ex) {
	         java.util.logging.Logger.getLogger(mainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	     }
		



Is This A Good Question/Topic? 0
  • +

Replies To: Java LookandFeels

#2 ChrisNt  Icon User is offline

  • D.I.C Addict

Reputation: 198
  • View blog
  • Posts: 563
  • Joined: 31-July 13

Re: Java LookandFeels

Posted 02 November 2013 - 04:27 PM

Put your code in a method and use SwingUtilities.updateComponentTreeUI( pass your frame ); at the end to update it. when radio button is selected call that method .
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,845
  • Joined: 18-April 07

Re: Java LookandFeels

Posted 02 November 2013 - 04:38 PM

Check out the following page...

http://docs.oracle.c...ml#programmatic

Scroll down to the topic "Changing the Look and Feel After Startup" and the check out the example code after that topic. This code can be put into its own method and called.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Test extends JFrame {

	JButton button;
	static Test ourTestForm;
	
	// Create our form and setup with a null layout for demo purposes
	public static void main(String[] args) {
		ourTestForm = new Test();
		ourTestForm.setSize(300,300);
		ourTestForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		ourTestForm.setLayout(null);
		ourTestForm.setVisible(true);
	}
	
	// Our constructor, add button and place it
	public Test() {
		button = new JButton("Click Me");
		button.setBounds(20,20,100,30);
		add(button);
		
		// When button clicked, kick off look and feel change to Motif
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
				} catch (ClassNotFoundException | InstantiationException
						| IllegalAccessException
						| UnsupportedLookAndFeelException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				// Update component tree of our form
				SwingUtilities.updateComponentTreeUI(ourTestForm);
			}
			
		});
	}

}



Was This Post Helpful? 0
  • +
  • -

#4 incredibleX  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 01-November 13

Re: Java LookandFeels

Posted 03 November 2013 - 12:50 AM

what would be this command for windows Clasic Look and feel
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");


Was This Post Helpful? 0
  • +
  • -

#5 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,845
  • Joined: 18-April 07

Re: Java LookandFeels

Posted 03 November 2013 - 10:07 AM

I believe the windows look and feel would be the class com.sun.java.swing.plaf.windows.WindowsLookAndFeel and of course this Look and Feel is only available on Windows. I hope that helps. :)
Was This Post Helpful? 0
  • +
  • -

#6 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 797
  • View blog
  • Posts: 2,422
  • Joined: 29-July 11

Re: Java LookandFeels

Posted 03 November 2013 - 11:30 AM

View PostChrisNt, on 02 November 2013 - 11:27 PM, said:

Put your code in a method and use SwingUtilities.updateComponentTreeUI( pass your frame ); at the end to update it. when radio button is selected call that method .


That's double the work. :)

The user will call setLookAdFeel() through the ActionListener which will execute on the event dispatch thread to update the look and feel, then updateComponentTree() will be called on the event dispatch thread to update the looks and feel again.

All you need to do is call setLookAndFeel().
Was This Post Helpful? 0
  • +
  • -

#7 ChrisNt  Icon User is offline

  • D.I.C Addict

Reputation: 198
  • View blog
  • Posts: 563
  • Joined: 31-July 13

Re: Java LookandFeels

Posted 03 November 2013 - 11:40 AM

http://docs.oracle.com/

Changing the Look and Feel After Startup

You can change the L&F with setLookAndFeel even after the program's GUI is visible. To make existing components reflect the new L&F, invoke the SwingUtilities updateComponentTreeUI method once per top-level container. Then you might wish to resize each top-level container to reflect the new sizes of its contained components. For example:

UIManager.setLookAndFeel(lnfName);
SwingUtilities.updateComponentTreeUI(frame);
frame.pack(); 

Was This Post Helpful? 1
  • +
  • -

#8 incredibleX  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 01-November 13

Re: Java LookandFeels

Posted 28 January 2014 - 11:26 PM

I've used Napkin Laf same as i use Nimbus, but it is giving me some error like : "Keys We don't Override []".
What is this error?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1