Java方法适用于Windows而不适用于Macintosh? [英] Java method works on windows but not Macintosh?

查看:102
本文介绍了Java方法适用于Windows而不适用于Macintosh?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的方法,用于隐藏 JInternalFrame 的标题栏。现在的困境是在Windows平台下方法工作,

I had a real weird method which is used to hide JInternalFrame's title bar. Now the dilemma is below method works on windows platform,

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

但不是在Macintosh上!任何专家都有任何想法可以解释内部过程使得这种方法在Mac上无法使用。

But not on Macintosh! Any experts have any idea which can explain internal process which makes this method not usable on Mac.

是否有任何方法可以在两个平台上隐藏 JInternalFrame 的标题栏?

And is there any method which may work on both platform to hide titlebar of JInternalFrame?

谢谢

推荐答案

在Mac OS X上,的一个实例com.apple.laf.AquaInternalFrameUI 定义内部框架的外观。您可以通过设置 isPalette 属性并在Mac OS X上禁用帧图标来最小化差异,如下所示。

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

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

这篇关于Java方法适用于Windows而不适用于Macintosh?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆