java – Windows上的JDialog扩展到Windows任务栏.任何解决方法?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Windows上的JDialog扩展到Windows任务栏.任何解决方法?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3194字,纯文字阅读大概需要5分钟。
内容图文
This question讨论了JFrame扩展到Windows任务栏的已知错误. An answer链接到错误报告(具有各种重复项)并提供解决方法.我发现问题也适用于JDialogs. JFrame解决方法不适用.是否有类似的解决方法使JDialogs在Windows上表现自己?
示例代码:
import javax.swing.*;
public class Demo extends JDialog {
public Demo() {
setSize(250,12500);
setVisible(true);
}
public static void main(String[] args) {
new Demo();
}
}
编辑:
看起来这不会在JDK中修复. This bug report结束时评论说“如果开发人员想要让他们的窗口在屏幕上完全可见,他们应该考虑检查屏幕插图本身[如下面的解决方案],并以不同的方式重新布局他们的组件,或者重新布局调用pack()后手动调整窗口大小,或使用支持screen-insets的布局管理器[与BorderLayout和GridBagLayout等更常见的布局管理器不同].
解决方法:
这基本上可以确保对话框“适合”指定的屏幕,方法是将其移动到指定设备的范围内并缩小它,使其左下边缘在指定设备的范围内.
这将查看设备边界和插入,以计算对话框可以驻留的“安全”区域.
public class TestScreenSize {
public static void main(String[] args) {
new TestScreenSize();
}
public TestScreenSize() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
} catch (InstantiationException ex) {
} catch (IllegalAccessException ex) {
} catch (UnsupportedLookAndFeelException ex) {
}
Test test = new Test();
test.setLayout(new BorderLayout());
test.setVisible(true);
System.exit(0);
}
});
}
public class Test extends JDialog {
public Test() {
setModal(true);
setLocation(0, 0);
setSize(2000, 2000);
}
@Override
public void setBounds(int x, int y, int width, int height) {
Rectangle bounds = getSafeScreenBounds(new Point(x, y));
if (x < bounds.x) {
x = bounds.x;
}
if (y < bounds.y) {
y = bounds.y;
}
if (width > bounds.width) {
width = (bounds.x + bounds.width) - x;
}
if (height > bounds.height) {
height = (bounds.y + bounds.height) - y;
}
super.setBounds(x, y, width, height);
}
}
public static Rectangle getSafeScreenBounds(Point pos) {
Rectangle bounds = getScreenBoundsAt(pos);
Insets insets = getScreenInsetsAt(pos);
bounds.x += insets.left;
bounds.y += insets.top;
bounds.width -= (insets.left + insets.right);
bounds.height -= (insets.top + insets.bottom);
return bounds;
}
public static Insets getScreenInsetsAt(Point pos) {
GraphicsDevice gd = getGraphicsDeviceAt(pos);
Insets insets = null;
if (gd != null) {
insets = Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration());
}
return insets;
}
public static Rectangle getScreenBoundsAt(Point pos) {
GraphicsDevice gd = getGraphicsDeviceAt(pos);
Rectangle bounds = null;
if (gd != null) {
bounds = gd.getDefaultConfiguration().getBounds();
}
return bounds;
}
public static GraphicsDevice getGraphicsDeviceAt(Point pos) {
GraphicsDevice device = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice lstGDs[] = ge.getScreenDevices();
ArrayList<GraphicsDevice> lstDevices = new ArrayList<GraphicsDevice>(lstGDs.length);
for (GraphicsDevice gd : lstGDs) {
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle screenBounds = gc.getBounds();
if (screenBounds.contains(pos)) {
lstDevices.add(gd);
}
}
if (lstDevices.size() > 0) {
device = lstDevices.get(0);
} else {
device = ge.getDefaultScreenDevice();
}
return device;
}
}
内容总结
以上是互联网集市为您收集整理的java – Windows上的JDialog扩展到Windows任务栏.任何解决方法?全部内容,希望文章能够帮你解决java – Windows上的JDialog扩展到Windows任务栏.任何解决方法?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。