嗨,我有几个具有默认最小/最大和恢复按钮的内部框架。它在默认状态下工作正常,但是当你恢复主框架时,它就不能正常工作。假设两个内部框架处于最小状态,一个处于最大状态状态。现在,如果您将主容器最大化,那么所有最小内部框架都会消失>请在下面找到代码。请找到随附的屏幕截图
package tryout;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
public class Test3 {
public static void main(String[] args) {
new Test3();
}
private int xpos = 0;
private int ypos = 0;
public Test3() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception exp) {
exp.printStackTrace();
}
DesktopPane pane = new DesktopPane();
pane.add(newInternalFrame());
pane.add(newInternalFrame());
pane.add(newInternalFrame());
JFrame frame = new JFrame();
frame.add(pane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public JInternalFrame newInternalFrame() {
JInternalFrame inf = new JInternalFrame("Blah", true, false, true, true);
inf.setLocation(xpos, ypos);
inf.setSize(100, 100);
inf.setVisible(true);
inf.repaint();
inf.revalidate();
xpos += 50;
ypos += 50;
return inf;
}
public class DesktopPane extends JDesktopPane {
@Override
public void doLayout() {
super.doLayout();
List<Component> icons = new ArrayList<Component>(25);
int maxLayer = 0;
for (Component comp : getComponents()) {
if (comp instanceof JInternalFrame.JDesktopIcon) {
icons.add(comp);
maxLayer = Math.max(getLayer(comp), maxLayer);
}
}
maxLayer++;
int x = 0;
for (Component icon : icons) {
int y = getHeight() - icon.getHeight();
icon.setLocation(x, y);
x += icon.getWidth();
setLayer(icon, maxLayer);
}
}
/* public void doLayout() {
super.doLayout();
List<Component> icons = new ArrayList<Component>(25);
for (Component comp : getComponents()) {
if (comp instanceof JInternalFrame.JDesktopIcon) {
icons.add(comp);
}
}
int x = 0;
for (Component icon : icons) {
int y = getHeight() - icon.getHeight();
icon.setLocation(x, y);
x += icon.getWidth();
}
}*/
}
}