简体   繁体   English

验证JPanel的问题

[英]Problems validating a JPanel

I am writing a GUI program whose main class extends JFrame implements ActionListener . 我正在编写一个GUI程序,其主类扩展JFrame实现ActionListener There are a number of elements on the GUI including some custom Widgets that extend JPanel . GUI上有许多元素,包括一些扩展JPanel自定义小部件。 The main Window has two instances of one of the Widgets, but only the first one refreshes properly after new data is loaded (the app can load data from a file and fill the ca. 25 fields of the GUI). 主窗口有一个Widgets的两个实例,但只有第一个实例在加载新数据后正确刷新(应用程序可以从文件加载数据并填充GUI的大约25个字段)。 The second instance of the custom Widget does not react (does not change values) after it has been previously used once. 自定义Widget的第二个实例在之前使用过一次之后不会做出反应(不会更改值)。 I am sorry there is no way to extract a small code snippet that would reproduce the problem, but I have used the paramString() method of JPanel (etc). 我很抱歉没有办法提取一个可以重现问题的小代码片段,但是我使用了JPanel (等)的paramString()方法。

The first time the widget is used (and everything is OK), I get this: ,197,73,862x82,invalid,layout=javax.swing.GroupLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.BevelBorder@2ef5774e,flags=9,maximumSize=,minimumSize=,preferredSize= 第一次使用小部件(并且一切正常),我得到:,197,73,862x82,无效,layout = javax.swing.GroupLayout,alignmentX = 0.0,alignmentY = 0.0,border = javax.swing.border。 BevelBorder @ 2ef5774e,旗帜= 9,MAXIMUMSIZE =,=的minimumSize,首选大小=

The second time the widget is used (and it is not reactive), I get this: 第二次使用小部件(并且它不是被动的),我得到这个:

,0,0,0x0,invalid,layout=javax.swing.GroupLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.BevelBorder@552d7308,flags=9,maximumSize=,minimumSize=,preferredSize=

I have additionally tried to revalidate() both the widget and its parent, but to no avail, this.myWidget.isValid() returns false (whereas the same method from other components in my application returns true). 我还试图重新验证()小部件及其父级,但无济于事, this.myWidget.isValid()返回false(而我的应用程序中其他组件的相同方法返回true)。

Any ideas? 有任何想法吗?

thanks, Peter 谢谢,彼得

I suppose when the widget returns 我想当小部件返回时

197,73,862x82,invalid,layout=javax.swing.GroupLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.BevelBorder@2ef5774e,flags=9,maximumSize=,minimumSize=,preferredSize=

the first numbers are x=197, y=73, width=862, height=82 . 第一个数字是x=197, y=73, width=862, height=82 This is just a guess but on the second time you get 这只是一个猜测,但第二次你得到

,0,0,0x0,invalid,layout=javax.swing.GroupLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.BevelBorder@552d7308,flags=9,maximumSize=,minimumSize=,preferredSize=

Which would mean x=0, y=0, width=0, height=0 then i can suggest you to try to manually set the size of your widget an 0x0 size is not a valid size. 这意味着x=0, y=0, width=0, height=0然后我可以建议您尝试手动设置窗口小部件的大小0x0大小不是有效大小。

Additionnally, i suggest that you change the call of revalidate() to repaint() for your Widget because revalidate() may not repaint the widget itself but only its sub-components 另外,我建议你为你的Widget更改revalidate()的调用repaint() ,因为revalidate()可能不会重新绘制小部件本身,而只重绘它的子组件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM