开发者

Dynamically Generate JComponent during runtime

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜