在 jsplitpane 中的 jscrollpane 中调整画布的大小问题 [英] Resizing issue with canvas within jscrollpane within jsplitpane

查看:33
本文介绍了在 jsplitpane 中的 jscrollpane 中调整画布的大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NetBeans GUI 编辑器创建一个应用程序,其中我想要一个 JSplitPane,其顶部组件将是 Canvas 内的 Canvascode>JScrollPane 底部组件将是一个 JTextArea 或类似的东西.

I'm creating an application using the NetBeans GUI Editor, in which I want to have a JSplitPane, the top component of which will be a Canvas within a JScrollPane and the bottom component will be a JTextArea, or something like that.

当我将分隔线向下拉,从而增加顶部组件的大小时,一切似乎都调整得很好.

When I pull the divider downwards, and thus increasing the size of the top component everything seem to resize just fine.

当我尝试向上推动分隔线时出现问题:分隔线似乎位于 Canvas 下方(也可能位于 JScrollPane 下方).

The problem appears when I'm trying to push the divider upwards: The divider seems to go beneath the Canvas (and maybe beneath the JScrollPane too).

我尝试了 JScrollPaneCanvas 的首选/最小/最大尺寸的各种组合,但似乎没有任何效果.

I have tried various combinations of the preferred/minimum/maximum sizes of the JScrollPane and Canvas but nothing seems to work.

这是 Netbeans 生成的可能与手头问题有关的代码部分:

This is the part of the code that Netbeans generated that may have something to do with the problem at hand:

jSplitPane1 = new javax.swing.JSplitPane();
jScrollPane1 = new javax.swing.JScrollPane();
canvas1 = new java.awt.Canvas();
jTextField1 = new javax.swing.JTextField();

jSplitPane1.setDividerLocation(300);
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

jScrollPane1.setViewportView(canvas1);

jSplitPane1.setTopComponent(jScrollPane1);

jTextField1.setText("jTextField1");
jSplitPane1.setRightComponent(jTextField1);

由于这是我的第一个问题,我不允许在问题中嵌入图片,所以我只发布链接:

Since this is my first question, I'm not allowed to embed an image in the question, so I will just post the link:

红色箭头表示分隔线的位置.

The red arrows indicate the position of the divider.

提前感谢您的时间.

推荐答案

在阅读了 davidbuzatto 的评论后,我在 google 上搜索了关于混合 AWT 和 Swing 组件的内容,我有点惊讶地发现这是一种糟糕的做法.

After reading the comment by davidbuzatto I googled about mixing AWT and Swing components and I was a little surprissed to find out that it is such a bad practice.

我在这里

重量级组件有自己的 Z 顺序.这就是为什么 Swing 和 AWT 不能组合在一个容器中的原因.如果是,则 AWT 组件将绘制在 Swing 组件的 TOP 上.

Heavyweight components have their own Z-ordering. This is the reason why Swing and AWT cannot be combined in a single container. If they are, the AWT components will be drawn on TOP of Swing components.

例如:当 AWT 组件与 JtabbedPane 一起使用时,它们不会在选项卡切换时消失.

For example: When AWT components are used with JtabbedPane, they do not disappear when the tabs are switched.

感谢 davidbuzatto 给我指路:-)

Thanks davidbuzatto for showing me the way :-)

这篇关于在 jsplitpane 中的 jscrollpane 中调整画布的大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆