2

I added a JTable in a JFrame using drag and drop in netbeans.

I was able to display the contents of the database but it is not like what i want to display, i want strings with newlines to be display as multiple lines.

i have a code here that query in the sqlite database and then displayed it in the table.

 public void Update_table_RFID(JTable x){
            try{
                String sql = " select RFID as 'RFID Tag', Word, ARF as 'Audio Recording File', " 
                           + " DateAdded as 'Date Added', TimeAdded as 'Time Added' "
                           + " from RFID";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                x.setModel(DbUtils.resultSetToTableModel(rs));
            }
            catch(Exception e){
                JOptionPane.showMessageDialog(null,e);
            }
        }

but the output i got instead is this:

enter image description here

what do i need to do to display the correct output of the query in the table?

CL.
  • 173,858
  • 17
  • 217
  • 259
Xue
  • 53
  • 5
  • 2
    You should use HTML presentation for multiline strings. Simply add `` tag before each string and `` after end of each string and replace all `\n` by `
    `tag. For this case you'll need your own table model or at least your own cell renderer. Also it's required to update height for each row in table. For this purpose see the method `JTable#setRowHeight(int row, int height)`. Also please read about [Tables in Swing](https://docs.oracle.com/javase/tutorial/uiswing/components/table.html)
    – Sergiy Medvynskyy Apr 13 '17 at 07:40
  • You should also try to do, what you want without database. And on success you can improve your program with data from DB. – Sergiy Medvynskyy Apr 13 '17 at 07:45
  • [Here](http://stackoverflow.com/questions/1783607/auto-adjust-the-height-of-rows-in-a-jtable) is a good example about adjusting of rows. – Sergiy Medvynskyy Apr 13 '17 at 07:50

0 Answers0