Results 1 to 5 of 5
Thread: Change the shape of JFrame
- 07-06-2009, 09:03 AM #1
Member
- Join Date
- Jun 2009
- Posts
- 43
- Rep Power
- 0
- 07-06-2009, 04:33 PM #2
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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!
- 07-06-2009, 10:37 PM #3
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.
Also, you can take a look at the first Google result on java mac os look and feelJava Code:try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.updateComponentTreeUI(this); } catch (Exception e) { // some problem you can handle if needed }
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.
- 07-09-2009, 12:58 PM #4
Member
- Join Date
- Jul 2009
- Posts
- 7
- Rep Power
- 0
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); } } } }
- 07-09-2009, 01:47 PM #5
Member
- Join Date
- Jul 2009
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Help with Move Shape
By romina in forum AWT / SwingReplies: 2Last Post: 12-09-2010, 03:25 AM -
How to make a Jframe un-focusable when another Jframe is active?
By Robert_85 in forum Advanced JavaReplies: 4Last Post: 04-22-2009, 11:02 PM -
Listener for JFrame size change
By Thez in forum AWT / SwingReplies: 10Last Post: 02-14-2008, 03:10 PM -
implementing shape
By sidkdbl07 in forum Java 2DReplies: 1Last Post: 01-12-2008, 06:42 PM -
How to change shape of JButton
By FaRuK in forum AWT / SwingReplies: 1Last Post: 05-19-2007, 12:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks