在运行时更改 JTextField 的位置
我正在使用 Java Swing。我创建一个文本字段和一个按钮。如果我单击该按钮,文本字段应向左移动 100。如何做到这一点?
Am using Java Swing. I create one text field and a button. If I click the button, the text field should move left by 100. How to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从一次移动 5px 的微调器转换为一次移动 100px 的按钮,留给读者作为练习。 ;)
Converting from the spinner that moves 5px at a time, to a button that moves 100px at a time, is left as an exercise for the reader. ;)
以下是 jtextfiled
构造一个新的 TextField。 JTextField(文档 doc、字符串文本、int 列)
构造一个使用给定文本存储模型和给定列数的新 JTextField。
列)
构造一个具有指定列数的新空 TextField。
构造一个使用指定文本初始化的新 TextField。
构造一个使用指定文本和列初始化的新 TextField。
您还可以使用
参考JTextField 类
编辑
要移动文本字段,需要两个类属性 x,y,每次单击时,根据需要移动更改 x 和 y 的值,然后在单击按钮时设置文本字段的边界。如下
following are different constructor for jtextfiled
Constructs a new TextField. JTextField(Document doc, String text, int columns)
Constructs a new JTextField that uses the given text storage model and the given number of columns.
columns)
Constructs a new empty TextField with the specified number of columns.
Constructs a new TextField initialized with the specified text.
Constructs a new TextField initialized with the specified text and columns.
also you can change different properties of jtextfield using methods like
refer Class JTextField
EDIT
to move the textfield take two class attributes x,y and on every click change the values of x and y as you want to move, then set bounds of textfield on click of the button.as follow
在构造函数中你可以这样设置
添加按钮的动作执行事件......
然后在动作事件中
in construtor u can set like this
Then add action performed event for button......
in the action event