Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
917 views
in Technique[技术] by (71.8m points)

java - Set Jtable/Column Renderer for booleans

Right now my Boolean values for my JTable display as JCheckBoxes. This would normally be fine but I would like to display them as either an alternative String or image. I can get them to display as true/false but I would like to display them as a checkmark (?) if true and nothing if false. Possibly an image but lets do a String first...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Create a custom renderer. Extend the DefaultTableCellRenderer and add your own code to display whatever you want. It could be a custom Icon or if the "checkmark" is a printable character than you can just set the renderer text to the appropriate character.

Read the JTable API and you will find a link to the Swing tutorial on "How to Use Tables" which will give more information about renderers.

If you need more help post your SSCCE showing the problems you are having creating the renderer.

Edit:

The tutorial shows how to add a custom renderer for a given class but it doesn't show how to add a custom renderer for a specific column. You would use:

table.getColumnModel().getColumn(...).setCellRenderer(...);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...