当 Windows 主题更改时,JInternalFrame 表现得很奇怪?
这是我的示例代码。我正在尝试将没有标题栏显示的 JInternalFrame
嵌入到 JFrame
中。
import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameUI;
class A{
public void doThis(){
JFrame fr = new JFrame();
fr.setSize(300,300);
JInternalFrame f = new JInternalFrame();
f.setSize(200,200);
BasicInternalFrameUI ui = (BasicInternalFrameUI) f.getUI();
ui.setNorthPane(null);
f.setVisible(true);
fr.add(f);
fr.setVisible(true);
}
}
class MainA{
public static void main(String a[]){
A obj = new A();
obj.doThis();
}
}
该代码工作正常,并根据要求在没有标题栏的 JFrame
中显示 JInternalFrame
,如下所示。
我仍然运行此 UI,同时当我尝试更改我的 XP 主题时(通过 Properties> >外观>>主题),UI 会自动重新绘制,再次显示带有标题栏的 JInternalFrame
,如下所示。
我只是无法理解这种奇怪的行为。我不知道这是 Java Swing 的问题还是与操作系统有关。请帮我解决这个问题!
当我显式编码将 titleBar 设置为 null 时,为什么 UI 会根据启用的标题栏的主题更改而重新绘制?
PS:使用的操作系统是 Windows XP,我不确定在 Linux 或其他版本的 Windows 中是否观察到相同的行为
This is my sample code. I am trying to embed a JInternalFrame
without titlebar display into a JFrame
.
import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameUI;
class A{
public void doThis(){
JFrame fr = new JFrame();
fr.setSize(300,300);
JInternalFrame f = new JInternalFrame();
f.setSize(200,200);
BasicInternalFrameUI ui = (BasicInternalFrameUI) f.getUI();
ui.setNorthPane(null);
f.setVisible(true);
fr.add(f);
fr.setVisible(true);
}
}
class MainA{
public static void main(String a[]){
A obj = new A();
obj.doThis();
}
}
The code works fine and displays a JInternalFrame
within a JFrame
without titlebar as per the requirement as shown below.
I still have this UI running and at the same time when I try to change my XP theme (via Properties>>Appearance>>Theme), the UI automatically repaints itself to show the JInternalFrame
with a titlebar again as shown below.
I just can't understand this bizarre behavior. I have no clue if this is an issue with Java Swing or if it is something related to the OS. Please help me with this!
Why is the UI repainting upon theme change with an enabled titlebar when I explicitly code for the titleBar to be set as null?
PS: OS used is Windows XP and I am not sure if the same behavior is observed in Linux or other versions of Windows
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“do”是 Java 中的关键字,因此该代码无法为我编译。这段代码确实如此。
一些注释/问题:
JInternalFrame
直接添加到JDesktopPane
以外的任何内容?JInternalFrame
的大小存在一些小问题。我怀疑这与代码中缺少validate()
/pack()
有关。由于这不是问题,我懒得进一步调查。结果
我在这里使用 Windows 7 得到了“空结果”。在更改(按顺序)时,
JInternalFrame
的标题栏没有重新出现:'do' is a keyword in Java, so that code does not compile for me. This code does.
Some notes/questions:
JInternalFrame
directly to anything other than aJDesktopPane
?JInternalFrame
when changing themes. I suspect it has to do with the lack ofvalidate()
/pack()
in the code. Since that was not the question, I could not be bothered investigating it further.Results
I got a 'null result' here using Windows 7. The title bar of the
JInternalFrame
did not re-appear at any time when changing through (in order):