简体   繁体   中英

Multiline feature in an editable jtable cell

I want to have multiline feature for JTable cells. Wherein the cell automatically expands and shrinks itself when user writes or deletes text in/from cell. I have set columns width, but it doesnt automatically adjust itself according to user's input, rather text beyond the width are not seen at all, but i have a requirement to fix on the width. Can anyone help me with this, to have self adjusting and multiline feature for jtable cell . Would be very thankful. Thanks in advance.

Several steps:

  • implement a custom renderer using a JTextArea as rendering component
  • implement a custom editor using a JTextArea inside a JScrollPane as editing component
  • add logic (aka: TableModelListener) which updates JTable's individual rowHeight based on the renderer's preferred size on receiving a change notification

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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