简体   繁体   English

JTable将2个迷你按钮添加到单元格中

[英]JTable add 2 mini button into a cell

I wanted to know how to add 2 small button into a cell. 我想知道如何在单元格中添加2个小按钮。 This is used for 'Quantity' column in my jtable. 这用于我的jtable中的“数量”列。

在此处输入图片说明

I want to do as the image above, user are allowed to edit the number inside or clicking add or minus the number, how do I do it? 我要像上面的图像那样做,允许用户编辑内部数字或单击加减数字,该怎么办?

The two arrows are part of a component called a Spinner . 这两个箭头是称为Spinner的组件的一部分。 You can use a JSpinner to create textbox and use the SpinnerNumberModel to allow it to use numerical values: 您可以使用JSpinner创建文本框,并使用SpinnerNumberModel使其使用数值:

JSpinner spinner = new JSpinner();
spinner.setModel(new SpinnerNumberModel());

You can read more about spinners in the Java documentation 您可以在Java文档中了解有关微调器的更多信息

To add it to a table, you will need a custom class which extends DefaultCellEditor . 要将其添加到表中,您将需要一个扩展DefaultCellEditor的自定义类。 A few examples can be found here: 一些示例可以在这里找到:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM