我正在将一个JTextArea添加到我的JPanel中,并将它设置为一个特定的位置,但由于某种原因,它根本不移动。我使用过setBounds()和setLocation(),但都没有用。以下是我停下来的内容:
JTextArea name_field=new JTextArea(1,10);
name_field.setBackground(color);
name_field.setBounds(100,100,600,420);
name_field.setLineWrap(true);
add(name_field);它一直在同一个位置创建文本字段:在中间的屏幕顶部。我唯一能做的就是通过添加name_field.setLineWrap(true)来改变它的宽度,这只会使我更加困惑。如果这是因为某种原因而不能工作,是否有其他方法移动和调整我的JTextArea大小?
发布于 2015-07-09 13:07:57
jpanel的默认布局是flowlayout .in order to work setBounds()应该是null layout.but它非常不鼓励使用空布局-- layout.you应该使用布局--有很多布局流、网格、框、..etc.you首先为您的面板确定适当的布局,然后使用它。
如果您将布局设置为null,那么您的代码应该可以工作.but dooont!
setLayout(null); //change jpanel layout to null
JTextArea name_field=new JTextArea(1,10);
name_field.setBackground(color);
name_field.setBounds(100,100,600,420);
name_field.setLineWrap(true);
add(name_field);https://stackoverflow.com/questions/31318300
复制相似问题