Does the Java method work on Windows, but not on a Macintosh?

I had a real weird method that is used to hide the JInternalFrame header line. Now the dilemma below works on the Windows platform,

 ((javax.swing.plaf.basic.BasicInternalFrameUI) aXInternalFrame.getUI()).setNorthPane(null); 

But not on a Macintosh! Any experts have an idea that can explain the internal process that makes this method unusable on a Mac.

And is there any method that can work on both platforms to hide the JInternalFrame header?

thanks

+7
source share
2 answers

On Mac OS X, an instance of com.apple.laf.AquaInternalFrameUI determines the appearance of internal frames. You can minimize inconsistencies by setting the isPalette property and disabling frame icons on Mac OS X, as shown below.

enter image description here

 import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.plaf.basic.BasicInternalFrameUI; /** @see http://stackoverflow.com/questions/7218971 */ public class InternalFrame { private static final int DELTA = 40; private JDesktopPane desktop = new JDesktopPane(); private int offset = DELTA; public InternalFrame() { JFrame f = new JFrame("Add Frame"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setPreferredSize(new Dimension(400, 400)); JPanel p = new JPanel(); p.add(new JButton(new AbstractAction("Add") { @Override public void actionPerformed(ActionEvent e) { createInternalFrame(); } })); f.add(p, BorderLayout.SOUTH); createInternalFrame(); f.add(desktop, BorderLayout.CENTER); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } private void createInternalFrame() { JInternalFrame internalFrame = new JInternalFrame( "Internal Frame");//, true, true, true, true); desktop.add(internalFrame); internalFrame.setLocation(offset, offset); offset += DELTA; if (System.getProperty("os.name").startsWith("Mac OS")) { internalFrame.putClientProperty("JInternalFrame.isPalette", true); } else { ((BasicInternalFrameUI) internalFrame.getUI()).setNorthPane(null); } internalFrame.add(createTabbedPane()); internalFrame.pack(); internalFrame.setVisible(true); } // take up some space private JTabbedPane createTabbedPane() { JTabbedPane jtp = new JTabbedPane(); createTab(jtp, "One"); createTab(jtp, "Two"); return jtp; } private void createTab(JTabbedPane jtp, String s) { jtp.add(s, new JLabel("TabbedPane " + s, JLabel.CENTER)); } public static void main(String args[]) { EventQueue.invokeLater(new Runnable() { @Override public void run() { InternalFrame myInternalFrame = new InternalFrame(); } }); } } 
+4
source

It could be a hairy swing corner. As far as I remember, this functionality was not added for swing until java 1.5 is gone.

Have you tried the Frame.setUndecorated method?

http://download.oracle.com/javase/1.5.0/docs/api/java/awt/Frame.html#setUndecorated%28boolean%29

If this does not work, you may need to go down and make some JNI in the base object with the window open. I should have done this for similar functionality in windows with 1.4 jvm.

+1
source

All Articles