• Post Reply Bookmark Topic Watch Topic
  • New Topic

JCheckbox DefaultCellEditor funny in JTable

 
S Baker
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to understand cell editors in JTable.

Below is the TableExample3.java from the JDK demo area.

I added one line, which explicitly sets a JCheckBox DefaultCellEditor on the last column, which is a Boolean object in the data model.

If you comment out my line, then you see a checkbox that works nicely.

If you include my line, then the checkbox acts a little funny. When you click on it, it temporarily shifts left, then shifts back.

Why does that happen??

I have another interesting question using the same example which I'll post in a separate message.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the checkbox acts a little funny. When you click on it, it temporarily shifts left, then shifts back.


Same as your other question you need to understand the difference between a renderer and an editor.

The default Boolean renderer displays the checkbox center aligned.

When you click on the cell your "custom editor" is invoked which uses the default JCheckbox you provided it as the editor which defaults to left alignment.

Look at the source code of the JTable to see how the JCheckBox alignment is customized when it is used as an editor. Do a search on "BooleanEditor".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!