首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >移动JTextArea

移动JTextArea
EN

Stack Overflow用户
提问于 2015-07-09 13:01:34
回答 1查看 421关注 0票数 1

我正在将一个JTextArea添加到我的JPanel中,并将它设置为一个特定的位置,但由于某种原因,它根本不移动。我使用过setBounds()setLocation(),但都没有用。以下是我停下来的内容:

代码语言:javascript
复制
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大小?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-09 13:07:57

jpanel的默认布局是flowlayout .in order to work setBounds()应该是null layout.but它非常不鼓励使用空布局-- layout.you应该使用布局--有很多布局流、网格、框、..etc.you首先为您的面板确定适当的布局,然后使用它。

如果您将布局设置为null,那么您的代码应该可以工作.but dooont!

代码语言:javascript
复制
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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31318300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档