最小化Jinternal框架而不单击按钮 [英] Minimizing Jinternal Frame without clicking the button

查看:92
本文介绍了最小化Jinternal框架而不单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在不点击jinternalframe右上角的最小化/最大化按钮的情况下最小化/最大化JinternalFrame?

Is there any way to minimize/maximize the JinternalFrame without clicking the minimize/maximize button at the top-right corner of the jinternalframe?

我跟着这个帖子< a href =https://stackoverflow.com/questions/6476525/programmatically-minimize-a-jinternalframe>以编程方式最小化JInternalFrame?,具体设置

I followed this thread programmatically minimize a JInternalFrame?, specifically set

jinterframe.setIcon(false)

但我没有'工作。

谢谢。

推荐答案

按我的预期工作,你必须检查 JInternalFrame# isIconifiable()(eeerght这个Veto真的是****)

works as I expected, you have to check JInternalFrame#isIconifiable() (eeerght this Veto is really ****)

import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyVetoException;
import javax.swing.*;
import javax.swing.plaf.basic.*;

public class InternalFrameUnMovable extends JFrame {

    private static final long serialVersionUID = 1L;
    public JDesktopPane desktop;

    public InternalFrameUnMovable() {
        desktop = new JDesktopPane();
        getContentPane().add(desktop);
        desktop.add(createInternalFrame(1, Color.RED));
        desktop.add(createInternalFrame(2, Color.GREEN));
        desktop.add(createInternalFrame(3, Color.BLUE));
    }

    private JInternalFrame createInternalFrame(int number, Color background) {
        JInternalFrame internal = new JInternalFrame("Frame" + number, true, true, true, true);
        internal.setBackground(background);
        internal.setVisible(true);
        int location = 50 * number;
        internal.setBounds(location, location, 300, 300);
        return internal;
    }

    public static void main(String args[]) throws PropertyVetoException {
        InternalFrameUnMovable frame = new InternalFrameUnMovable();
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setSize(600, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        try {// Activate first internal frame
            JInternalFrame[] frames = frame.desktop.getAllFrames();
            frames[0].setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
        JInternalFrame[] frames = frame.desktop.getAllFrames();// Make first internal frame unmovable
        for (int i = 0; i < frames.length; i++) {
            JInternalFrame f = frames[i];
            if (f.isIconifiable()) {
                f.setIcon(true);
            }
        }
        /*JInternalFrame f = frames[0];
        BasicInternalFrameUI ui = (BasicInternalFrameUI) f.getUI();
        Component north = ui.getNorthPane();
        //MouseMotionListener[] actions = (MouseMotionListener[]) north.getListeners(MouseMotionListener.class);
        MouseMotionListener[] actions = north.getListeners(MouseMotionListener.class);
        for (int i = 0; i < actions.length; i++) {
        north.removeMouseMotionListener(actions[i]);
        }*/
    }
}

这篇关于最小化Jinternal框架而不单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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