Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Look & Feel

  1. #1
    Member
    Join Date
    Jun 2010
    Posts
    48
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Look & Feel

    Hello guys,

    Anyone can tell me why I don't see different look&feels? This is my main method:

    public static void main(String[ ] args) {
    		javax.swing.SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				JFrame f = createAndShowGUI();
     
    				try {
    					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    //					UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    //					UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    					javax.swing.SwingUtilities.updateComponentTreeUI(f);
    				} catch(Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Look & Feel

    I believe you must load the look and feel before making your window visible.

  3. #3
    Member
    Join Date
    Jun 2010
    Posts
    48
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: Look & Feel

    Quote Originally Posted by helloworld922 View Post
    I believe you must load the look and feel before making your window visible.
    I tried. This method actually refreshes the JFrame but it is still the same - look&feel doesn't change:
    javax.swing.SwingUtilities.updateComponentTreeUI(JFrame frame);

    Here is the way I try to do it:
    	private static JFrame createAndShowGUI() {
    //		JFrame.setDefaultLookAndFeelDecorated(true);
    		JFrame frame = new JFrame("Show Stack");
    		try {
    			UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    		StacksModel model = new StacksModel();
    		ShowStacks d = new ShowStacks(model);
    		List stacks = model.getModels();
    		for(ListIterator i = stacks.listIterator(); i.hasNext(); ) {
    			CardStack m = (CardStack) i.next();
    			m.addObserver(d);
    		}
    		JPanel cmd = new JPanel();
    		RoundButton button = new RoundButton("RUN");
    		button.setActionCommand("RUN");
    		JComboBox fromList = new JComboBox(model.getNames());
    		fromList.setActionCommand("FROM");
    		JComboBox toList = new JComboBox(model.getNames());
    		toList.setActionCommand("TO");
    		JLabel fromLabel = new JLabel("From:");
    		JLabel toLabel = new JLabel("To:");
    		cmd.add(fromLabel);
    		cmd.add(fromList);
    		cmd.add(button);
    		cmd.add(toLabel);
    		cmd.add(toList);
    		TestController controller = new TestController(model);
    		button.addActionListener(controller);
    		toList.addActionListener(controller);
    		fromList.addActionListener(controller);
    		frame.getContentPane().add(cmd, BorderLayout.NORTH);
    		JPanel p = new JPanel();
    		p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
    		p.add(d);
    		frame.getContentPane().add(p, java.awt.BorderLayout.CENTER);
     
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.pack();
    		frame.setVisible(true);
     
    		return frame;
    	}
     
    	ShowStacks() {
    		createAndShowGUI();
    	}
     
    	public static void main(String[ ] args) {
     
    		javax.swing.SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				JFrame f = createAndShowGUI();
     
    /**				try {
    					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    					UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    					UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    					javax.swing.SwingUtilities.updateComponentTreeUI(f);
    				} catch(Exception e) {
    					e.printStackTrace();
    				}
    */			}
    		});
    	}
    }

  4. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Look & Feel

    Have you gone through the tutorial?
    How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)

    db

Similar Threads

  1. Replies: 2
    Last Post: October 14th, 2009, 10:10 AM