Why jframe hides taskbar when maximized?(为什么jframe在最大化时隐藏任务栏?)
问题描述
我在我的 jFrame 中使用 setUndecorated(true);
和 getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
.这很好用,但是现在当我最大化我的框架时,它遍布整个窗口,甚至任务栏都不可见.如何使框架不隐藏任务栏?
I'm using setUndecorated(true);
and getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
in my jFrame. This works great but now when I maximized my frame it spreads all over the window even taskbar is not visible. What can I do to make frame not to hide taskbar?
此外,当我多次最大化最小化我的框架时,光标会更改为这个 <->
,当光标位于框架的边界时,它通常用于更改框架的大小.有什么我可以做的吗?
Also when I maximize minimize my frame multiple times the cursor is changed to this <->
which is generally used change size of frame when cursor is on the border of frame. Is there anything I can do for this?
一个小代码就可以重现这个东西:
A small code then can reproduce the thing:
import javax.swing.JFrame;
import javax.swing.JRootPane;
public class Demo extends JFrame {
public Demo() {
setSize(250,125);
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
setVisible(true);
}
public static void main(String[] args) {
new Demo();
}
}
推荐答案
这是一个已知错误:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4737788
来自此链接的引用:
一种解决方法是继承 JFrame 和覆盖 setExtendedState 方法,之前捕获任何最大化事件它们发生并设置最大值适当的框架边界在调用超类之前setExtendedState 方法.
A workaround is to subclass JFrame and override the setExtendedState method, catching any maximize events before they happen and setting the maximum bounds of the frame appropriately before calling the superclass's setExtendedState method.
import java.awt.*;
import javax.swing.*;
public class PFrame extends JFrame
{
private Rectangle maxBounds;
public PFrame()
{
super();
maxBounds = null;
}
//Full implementation has other JFrame constructors
public Rectangle getMaximizedBounds()
{
return(maxBounds);
}
public synchronized void setMaximizedBounds(Rectangle maxBounds)
{
this.maxBounds = maxBounds;
super.setMaximizedBounds(maxBounds);
}
public synchronized void setExtendedState(int state)
{
if (maxBounds == null &&
(state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH)
{
Insets screenInsets = getToolkit().getScreenInsets(getGraphicsConfiguration());
Rectangle screenSize = getGraphicsConfiguration().getBounds();
Rectangle maxBounds = new Rectangle(screenInsets.left + screenSize.x,
screenInsets.top + screenSize.y,
screenSize.x + screenSize.width - screenInsets.right - screenInsets.left,
screenSize.y + screenSize.height - screenInsets.bottom - screenInsets.top);
super.setMaximizedBounds(maxBounds);
}
super.setExtendedState(state);
}
}
这篇关于为什么jframe在最大化时隐藏任务栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么jframe在最大化时隐藏任务栏?
基础教程推荐
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01