如何让JInternalFrame填充Container并禁用拖动功能? [英] how to make JInternalFrame fill the Container and disable the dragging feature?
问题描述
我正在开发一个项目,大型机中有JInternalFrames。现在,我们需要让它们成为JFrame。我正在考虑使用JFrame来保存JInternalFrame。问题是内部框架的标题栏在那里,用户可以拖动它。
I'm working on a project, there are JInternalFrames in the mainframe. Now, we need to let them to be JFrame. I'm considering using a JFrame to hold on JInternalFrame. The problem is that the titlebar of Internalframe is there, and user can drag it around.
有没有办法让内部框架像JFrame中的窗格一样工作?
在互联网上搜索后,我发现有人删除了标题窗格。
Is there any way to make the Internal frame work like a pane in the JFrame? After searching on the Internet, I found somebody removes the titlepane.
你对此有什么好主意吗?
Do you have any good idea on this?
谢谢你!
更新:
也许我走错了路。真正的问题是JInternal框架无法离开主框架,或者任何方式使它看起来像框架的外侧?
update: Maybe I was on the wrong track. The real problem is the JInternal frame can not get out of the main Frame, or any way to make it look like it's out side of the frame?
推荐答案
有没有办法让内部框架像
JFrame中的窗格一样工作
Is there any way to make the Internal frame work like a pane in the JFrame
我不确定 pane 的含义,但我想像 JPanel
?当然你可以,但为什么,这将是我的问题,除非你想要某种快速的浮动面板,但是你说你不想要它可拖动?所以我不确定你的动机,让我厌倦了回答......
Im not sure by what you mean by pane, but I guess like a JPanel
? Of course you can but why, would be my question, unless you want some sort of quick floating panel, but than you say you dont want it draggable? So Im bit unsure of your motives and makes me weary to answer....
问题是内框的标题栏在那里
The problem is that the titlebar of Internalframe is there
以下是删除 titlepane 的代码(找到它这里):
Well Here is code to remove the titlepane (found it 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
无法移动c $ c> s使它可以移动,但重要的是要注意它没有必要删除 MouseListener
s作为用于使其不可分割的方法将删除 NorthPane
,其中也添加了 MouseListener
,因此我们不必自行删除它。:
And I found this to make JInternalFrame
unmovable by removing the MouseListener
s which make it movable, but it is important to note its not necessary to remove the MouseListener
s as the method used to make it undraggable will remove the NorthPane
which the MouseListener
is added too thus its unnecessary for us to remove it ourselves.:
//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
填充容器
只需在参数<$ c的 JInternalFrame
上调用 setSize(int width,int height)
$ c> JDesktopPane s width
和 height
( JDesktopPane
将通过覆盖 getPreferredSize()
来调整大小。
Simply call setSize(int width,int height)
on JInternalFrame
with parameters of the JDesktopPane
s width
and height
(JDesktopPane
will be sized via overriding 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);
}
}
这篇关于如何让JInternalFrame填充Container并禁用拖动功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!