开发者

Dynamically Generate JComponent during runtime

开发者 https://www.devze.com 2023-03-22 17:18 出处:网络
got anyways to dynamically generate开发者_如何学C JComponent like JTextField, JCombobox? What i try is work.., but can only add-on once which\'s declare as global variable. Got anyway likes changing v

got anyways to dynamically generate开发者_如何学C JComponent like JTextField, JCombobox? What i try is work.., but can only add-on once which's declare as global variable. Got anyway likes changing variable Name during every runtime?


You can't assign a uniques name to every component you dynamically generate.

As you define the text fields you need to add them to a List (or some other data structure). Then you can access the textfields individually from the List.

List<JTextField> textFields = new ArrayList<JTextField>();

for (int i = 0; i < 10; i++)
{
    JTextField textField = new JTextField();
    textFields.add( textField );
    somePanel.add( textField );
}

somePanel.revalidate();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号