txDiv0
当尝试除以 0 时,应该显示文本。它最初设置为不可见。代码可以正常工作,但仅当我单击框架边框时才会显示文本,好像要使其变大一样。使帧字面上高一个像素会使该字段显示出来。
GUIbuilder 生成的代码:
private javax.swing.JTextField txDiv0;
...
txDiv0 = new javax.swing.JTextField();
...
txDiv0.setText("Division by 0 is undefined");
...
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txDiv0, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
.addGap(0, 11, Short.MAX_VALUE)
.addComponent(txDiv0, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
);
...
pack();
以下是我试图让它出现的方法:
txDiv0.setVisible(true);
System.out.println();
(那里的 println 向我展示了代码确实执行了。)
除非我几乎不摆动框架的边缘,否则文本字段永远不会出现。