如何在Java中的表中添加一个组合框 [英] how to add a combobox into table in java

查看:78
本文介绍了如何在Java中的表中添加一个组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有问题,需要您的帮助.
我有一个带有6(1-> 6)列的表,而2,3,5列是组合框列.
单击此列上的任何单元格时,将出现一个组合框,并允许用户选择
来自此组合框端的数据,然后返回普通单元格.

如果知道,请帮助我!
(我是Java初学者)

在此先感谢

Hi all,
I have a problem tat need your help.
I have a table with 6(1->6) column and column 2,3,5 are combobox column.
when click on any cell on this columns, a combobox will appear and allow user choice
data from this combobox end then return normal cell.

if you know, please help me!
(I am a Java beginer)

thanks in advance

推荐答案

如果要分隔组合框中显示的值和文本,则必须创建一个同时包含两个值的对象.

下面的代码显示了如何执行此操作.只需创建此类的对象并将其添加到组合框即可.使用getId()获得对象的ID,使用getDescription()获得文本. toString()方法确保描述将是组合框中显示的文本.


If you want to separate the value and text that are shown in the combobox you have to create an object that holds both values.

The code below shows how to do this. Just create objects of this class and add them to the combobox. With getId() you get the ID of the object and with getDescription() you get the text. The toString() method makes sure that the description will be the text shown in the combobox.


class Item {
		private int id;
		private String description;

		public Item(int id, String description) {
			this.id = id;
			this.description = description;
		}

		public int getId() {
			return id;
		}

		public String getDescription() {
			return description;
		}

		public String toString() {
			return description;
		}
	}


这篇关于如何在Java中的表中添加一个组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆