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

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

问题描述

我正在使用NetBeans GUI编辑器创建一个应用程序,我希望在其中有一个 JSplitPane ,其顶部组件将是 JScrollPane 中的> Canvas ,底部组件将是 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).

我尝试了<$ c $的首选/最小/最大尺寸的各种组合c> JScrollPane 和 Canvas 但似乎没有任何效果。

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的评论之后,我搜索了关于混合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.

我找到了对我的问题最准确的答案这里

I found the most accurate answer to my question here


重量级组件有自己的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中调整canvas的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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