i would like to insert multiple strings in the same cell in a jtable line by line.This is the way i added the data into jtable
String Model,Brand,Serial;
String itemdetails=Model+Brand+Serial
model.addRow(new Object[]{itemdetails,amountText.getText()});
Here what the problem is,getting the output in single line,But i want output like this in a jtbale's cell.
Model //it is string coming from database
Brand //it is string coming from database
Serial //it is string coming from database
i have tried this but its working only data within double quotes,not with strings.
"<html>lineOne <br/> lineTwo </html>"
Your for loop is incorrectly close :
So, without doing anything special, I can make
<html>...<br>...</html>
work just fine...Maybe there's something else in your code, which you're not showing us, which is causing the problem...
This is going past the original question, BUT, the
TableModel
represents the data it's backing, it provides the structure for theJTable
to show it.So, given a bunch of "disconnected" values, it's the
TableModel
which is going to "sew" them together, based on your requirements.The following example simple splits each line of the previous poem in a an array, when each line represents a element.
This is then wrapped again so each section of the poem is an array of lines...
The example then uses a custom
TableModel
, which when asked for the value of the cell, takes the given "section" and builds aString
out of each line, wrapping into a<html>
basedString
.Further, you need to click the Add button to add each new line before it can be displayed
Take a look at How to Use Tables for more details