0

I wanted to know how to add 2 small button into a cell. This is used for 'Quantity' column in my jtable.

enter image description here

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?

Chan Chun Weng
  • 876
  • 2
  • 16
  • 32

1 Answers1

2

The two arrows are part of a component called a Spinner. You can use a JSpinner to create textbox and use the SpinnerNumberModel to allow it to use numerical values:

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

You can read more about spinners in the Java documentation

To add it to a table, you will need a custom class which extends DefaultCellEditor. A few examples can be found here:

Community
  • 1
  • 1
Jorel Ali
  • 383
  • 1
  • 3
  • 9