开发者

NetworkInterface's getNetworkInterfaces() to JComboBox

First Question

NetworkInterface.getNetworkInterfaces();

returns a Enumeration type. each element of the Enumeration has a getDisplayName() method which returns a string such as en0, en1, vnic1 etc. Now I would like to make these strings into a JComboBox. I'm Stuck trying to add these through

jComboBox1.setModel("Some code here");

One more question out of curiosity.. Why did the folks wo开发者_如何学Pythonrking on Java decide to use Enumeration instead of NetworkInterface?


Doesn't simply adding string to JComboBox works.

jComboBox.add(NetworkInterface.getNetworkInterfaces().en1.getDisplayName())

or if you want to handle it in model then write a class that implements ListCellRenderer and in its method getListCellRendererComponent() call your method of getting name and return that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜