Widgets in JTable
columns are expected to be not distinguishable from normal ones, right? There seems to be behavioral difference, take Swing documentation example and move mouse over checkboxes in the Vegetarian column... They don't react at all. I understand that those are just widget surrogates, so highlighting has to be done manually, so how would I fix this? I tried widget.requestFocusInWindow();
in mouseMoved()
for the surrogate widget event handler without success. Any other workaround?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Both
JTable
andJTree
use the flyweight pattern for rendering. The default renderer & editor have no intrinsic mouse-over behavior. You have to supply the desired behavior yourself, as @Max shows.You can create your own cell renderer that applies a rollover effect. Then, add a mouse listener that tracks the mouse movement and repaints the relevant cells. You need to apply the effect to the current cell under the cursor and clear the previous cell.
Below is a short example that demonstrates this approach on a checkbox renderer. The example extends default
BooleanRenderer
. The only change isgetModel().setRollover(...)
ingetTableCellRendererComponent()
.Jtable dont put real components into cells. They only use the component's paint methods to render the cell content.