我的英语很差,所以请原谅我的语法错误。我是java swings的新手,我的目的是动态创建许多jintenalframe,并且每个jintenalframe都是可移动的,即可以自由拖动并保留在任何地方,这是我通过组件移动器类实现的。现在我面临的问题是我无法调整这些内部框架的大小。每当我调整这些 jinternalFrames 的大小时,它们都会恢复到相同的大小。我什至已经使用组件侦听器注册了调整大小事件,下面的代码描述了:
this.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent ce)
{
setDinamicSize(ce)
}
});
private void setDinamicSize(ComponentEvent ce)
{
JInternalFrame tempFrame = (JInternalFrame)ce.getSource();
tempFrame.setSize(new Dimension(tempFrame.getAlignmentX(),tempFrame.getAlignmenty()));
}
Run Code Online (Sandbox Code Playgroud)
请帮帮我。提前致谢
JDesktopPane是 s 的容器JInternalFrame,它负责诸如定位和(如果您已正确构建内部框架)调整大小之类的事情...

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class TestDesktopPane {
public static void main(String[] args) {
new TestDesktopPane();
}
public TestDesktopPane() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
JDesktopPane pane = new JDesktopPane();
JInternalFrame inFrame = new JInternalFrame("No Hands", true, true, true, true);
inFrame.setBounds(10, 10, 100, 100);
inFrame.setVisible(true);
pane.add(inFrame);
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(pane);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
查看如何使用内部框架了解更多详细信息
| 归档时间: |
|
| 查看次数: |
2513 次 |
| 最近记录: |