- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在做一个项目,在主机中有JInternalFrames。现在,我们需要让它们成为 JFrame。我正在考虑使用 JFrame 来保存 JInternalFrame。问题是 Internalframe 的标题栏在那里,用户可以拖动它。
有没有办法让内部框架像 JFrame 中的 Pane 一样工作?在网上搜索后,我发现有人删除了标题栏。
你有什么好的想法吗?
谢谢!
更新:也许我走错了路。真正的问题是 JInternal 框架无法脱离主框架,或者有什么办法让它看起来像是在框架的外面?
最佳答案
Is there any way to make the Internal frame work like a pane in the JFrame
我不确定您所说的 Pane 是什么意思,但我想应该是JPanel
?当然可以,但是为什么,这是我的问题,除非你想要某种快速 float 面板,但你说你不希望它可拖动?所以我有点不确定你的动机,让我厌倦了回答....
The problem is that the titlebar of Internalframe is there
下面是删除titlepane 的代码(找到它 here ):
//remove title pane http://www.coderanch.com/t/505683/GUI/java/JInternalframe-decoration
BasicInternalFrameTitlePane titlePane =(BasicInternalFrameTitlePane)((BasicInternalFrameUI)jInternalFrame.getUI()).getNorthPane();
jInternalFrame.remove(titlePane);
and user can drag it around.
我发现这可以通过删除使其可移动的 MouseListener
来使 JInternalFrame
不可移动,但重要的是要注意它没有必要删除 MouseListener
作为用于使其成为不可拖动 的方法将删除 NorthPane
也添加了 MouseListener
因此它对我们来说是不必要的自己删除它。:
//remove the listeners from UI which make the frame move
BasicInternalFrameUI basicInternalFrameUI = ((javax.swing.plaf.basic.BasicInternalFrameUI) jInternalFrame.getUI());
for (MouseListener listener : basicInternalFrameUI.getNorthPane().getMouseListeners()) {
basicInternalFrameUI.getNorthPane().removeMouseListener(listener);
}
根据你的标题:
how to make
JInternalFrame
fill the Container
只需使用 JDesktopPane
的 width
参数在 JInternalFrame
上调用 setSize(int width,int height)
和 height
(JDesktopPane
将通过覆盖 getPreferredSize()
调整大小)。
这会给我们这个:
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.event.MouseListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.SwingUtilities;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import javax.swing.plaf.basic.BasicInternalFrameUI;
/**
*
* @author David
*/
public class Test {
public Test() {
createAndShowGUI();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Test();
}
});
}
private void createAndShowGUI() throws HeadlessException {
JFrame frame = new JFrame();
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final JDesktopPane jdp = new JDesktopPane() {
@Override
public Dimension getPreferredSize() {
return new Dimension(300, 300);
}
};
frame.setContentPane(jdp);
frame.pack();
createAndAddInternalFrame(jdp);
frame.setVisible(true);
}
private void createAndAddInternalFrame(final JDesktopPane jdp) {
JInternalFrame jInternalFrame = new JInternalFrame("Test", false, false, false, false);
jInternalFrame.setLocation(0, 0);
jInternalFrame.setSize(jdp.getWidth(), jdp.getHeight());
//remove title pane http://www.coderanch.com/t/505683/GUI/java/JInternalframe-decoration
BasicInternalFrameTitlePane titlePane = (BasicInternalFrameTitlePane) ((BasicInternalFrameUI) jInternalFrame.getUI()).getNorthPane();
jInternalFrame.remove(titlePane);
/*
//remove the listeners from UI which make the frame move
BasicInternalFrameUI basicInternalFrameUI = ((javax.swing.plaf.basic.BasicInternalFrameUI) jInternalFrame.getUI());
for (MouseListener listener : basicInternalFrameUI.getNorthPane().getMouseListeners()) {
basicInternalFrameUI.getNorthPane().removeMouseListener(listener);
}
*/
jInternalFrame.setVisible(true);
jdp.add(jInternalFrame);
}
}
关于java - 如何让 JInternalFrame 填充容器并禁用拖动功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14600332/
我是一名优秀的程序员,十分优秀!