有没有办法在不单击 jinternalframe 右上角的最小化/最大化按钮的情况下最小化/最大化 JinternalFrame ?
我关注了这个线程以编程方式最小化 JInternalFrame? https://stackoverflow.com/questions/6476525/programmatically-minimize-a-jinternalframe,具体设定
jinterframe.setIcon(false)
但我没有工作。
Thanks.
按我的预期工作,你必须检查JInternalFrame#isIconabilible() http://docs.oracle.com/javase/6/docs/api/javax/swing/JInternalFrame.html#isIconifiable%28%29(呃这个否决权真是****)
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]);
}*/
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)