Results 1 to 5 of 5
  1. #1
    kiki2009 is offline Member
    Join Date
    Jun 2009
    Posts
    43
    Rep Power
    0

    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.:confused:

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    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.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default Look and feel

    Hi kiki. :D

    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.
    Java 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. ;)
    Last edited by tim; 07-06-2009 at 10:39 PM.
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  4. #4
    raghu_lzybns is offline Member
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    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.

    Java 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);
    			}
    		}
    	}
    }

  5. #5
    stevemilw is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Help with Move Shape
    By romina in forum AWT / Swing
    Replies: 2
    Last Post: 12-09-2010, 03:25 AM
  2. Replies: 4
    Last Post: 04-22-2009, 11:02 PM
  3. Listener for JFrame size change
    By Thez in forum AWT / Swing
    Replies: 10
    Last Post: 02-14-2008, 03:10 PM
  4. implementing shape
    By sidkdbl07 in forum Java 2D
    Replies: 1
    Last Post: 01-12-2008, 06:42 PM
  5. How to change shape of JButton
    By FaRuK in forum AWT / Swing
    Replies: 1
    Last Post: 05-19-2007, 12:56 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
  •