Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTable.setValueAt does not fold string

Status
Not open for further replies.

mydavor

Programmer
Mar 21, 2004
41
0
0
AU
javax.swing.JTable tableEnv = new javax.swing.JTable();
tableEnv.setValueAt((Object)EnvText1, 0, 0);
String EnvText1 = "ENERGY USE AND GREENHOUSE EMISSIONS" + "\n " + "What effect will the proposal have on energy" + "\n " + "consumption and greenhouse gas emissions";

I am trying to insert a string in row 0, column 0 of the above JTable. But EnvText1's new line characters ("\n") get lost and EnvText1 is one contnuous string. Is there a way to insert a string in a JTable field so that nicely folds on \n ??

 
The default TableCellRenderer in a JTable is an instance of JLabel, and that displays only a line of text. You have several options:

Either use HTML (described here, stated here).

Another option is changing (extending) the DefaultTableCellRenderer.

Or you choose the really flexible option (that's what I do regularly), dive into it and look at How to use Tables, they explain how you create your own TableCellRenderers and TableCellEditors.

haslo@haslo.ch - www.haslo.ch​
 
please remember in the future that this forum is meant for J2EE issues, not J2SE ( forum269 ).

Cheers


--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top