Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-06-2009, 10:03 AM
Member
 
Join Date: Jun 2009
Posts: 15
Rep Power: 0
kiki2009 is on a distinguished road
Default Change the shape of JFrame
How to change the shape of JFrame in different shape , and also make it interface look alike Mac Windows Frame.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-06-2009, 05:33 PM
Senior Member
 
Join Date: Mar 2009
Posts: 376
Rep Power: 1
Singing Boyo is on a distinguished road
Default
You can't change the shape of components (at least not most of them, haven't looked at all the API docs) in either AWT or Swing. As for the way it looks, probably setting the look and feel, but I'm not sure what L&F you would want.
__________________
So you came along and found Java? Randomly?
Well then, you're just like me!
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-06-2009, 11:37 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 406
Rep Power: 3
tim is on a distinguished road
Default Look and feel
Hi kiki.

The code below will update your java frame ("this") with the systems default look and feel. So, if you run it on Mac OS, and the look and feel is installed, it should look like a Mac OS application, i.e. in the correct "shape". You can place it in your frames constructor.
Code:
try {                
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
    // some problem you can handle if needed
}
Also, you can take a look at the first Google result on java mac os look and feel

Good luck kiki.
__________________
Eyes dwelling into the past are blind to what lies in the future.

Last edited by tim; 07-06-2009 at 11:39 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-09-2009, 01:58 PM
Member
 
Join Date: Jul 2009
Posts: 7
Rep Power: 0
raghu_lzybns is on a distinguished road
Default Look and Feel
I can understand that u are looking for for LookAndFeel.

Here is a sample code to understand....try it.

This looks like hefty code but simple to understand.

Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GettingAndSettingLAF {
	JFrame frame;
	JTextArea txtArea;
	public static void main(String args[]) {
		GettingAndSettingLAF mc = new GettingAndSettingLAF();
	}

	public GettingAndSettingLAF(){
		frame = new JFrame("Change Look");
		UIManager.LookAndFeelInfo lookAndFeels[] = UIManager.getInstalledLookAndFeels();
		JPanel panel = new JPanel();
		JPanel panel1 = new JPanel();
		txtArea = new JTextArea(5, 15);
		JScrollPane sr = new JScrollPane(txtArea);
		panel1.add(sr);
		for(int i = 0; i < lookAndFeels.length; i++){
			JButton button = new JButton(lookAndFeels[i].getName());
			button.addActionListener(new MyAction());
			panel.add(button);
		}
		frame.add(panel1,BorderLayout.NORTH);
		frame.add(panel, BorderLayout.CENTER);
		frame.setSize(300, 200);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.setVisible(true);
	}

	public class MyAction implements ActionListener{
		public void actionPerformed(ActionEvent ae){
			Object EventSource = ae.getSource();
			String lookAndFeelClassName = null;
			UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();
			for(int i = 0; i < looks.length; i++){
				if(ae.getActionCommand().equals(looks[i].getName())){
					lookAndFeelClassName = looks[i].getClassName();
					break;
				}
			}
			try{
				UIManager.setLookAndFeel(lookAndFeelClassName);
				txtArea.setText(lookAndFeelClassName);
				SwingUtilities.updateComponentTreeUI(frame);
			}
			catch(Exception e){
				JOptionPane.showMessageDialog(frame, "Can't change look and feel:" + lookAndFeelClassName, "Invalid PLAF", JOptionPane.ERROR_MESSAGE);
			}
		}
	}
}
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-09-2009, 02:47 PM
Member
 
Join Date: Jul 2009
Posts: 6
Rep Power: 0
stevemilw is on a distinguished road
Default
i concur and do so solemly agree
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a Jframe un-focusable when another Jframe is active? Robert_85 Advanced Java 4 04-23-2009 12:02 AM
Listener for JFrame size change Thez AWT / Swing 10 02-14-2008 04:10 PM
implementing shape sidkdbl07 Java 2D 1 01-12-2008 07:42 PM
Help with Move Shape romina AWT / Swing 1 08-07-2007 06:27 AM
How to change shape of JButton FaRuK AWT / Swing 1 05-19-2007 01:56 PM


All times are GMT +2. The time now is 06:39 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org