0

Here is my code, it does get data and paste it in the Text Area as I want it to do, I was just wondering if I could change it so that I could edit how it gets outputted, and add line breaks etc?

btnLeaderBoardUpdate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            String sql3 ="Select * from honscores group by Name order by Kills";
            ResultSet rsz;
            try {
                PreparedStatement stz = conn.prepareStatement(sql3);
                rsz = stz.executeQuery();
                LeaderBoard = rsz.toString();

                while(rsz.next()){
                    ArrayList<String> record = new ArrayList<String>();
                    ResultSetMetaData metaData = rsz.getMetaData();
                    int columns = metaData.getColumnCount();

                    for (int i = 1; i <= columns; i++) {
                            String value = rsz.getString(i);
                            record.add(value);
                }
                    for (int i=1;i<columns;i++) {
                        txtLeaderBoard_1.append(record.toString());
                    }

        }   
            } catch(Exception e) {
                JOptionPane.showMessageDialog(null, e);
            }


        }
    });
AceFire6
  • 103
  • 1
  • 10

2 Answers2

0

It sounds like maybe a Java Swing "Listbox" might be a better choice for you than a "TextArea".

paulsm4
  • 114,292
  • 17
  • 138
  • 190
0

You have to add the separators and any decorators to the "rendering" loop. It's independent from the query. (Eg dummy example:)

    for (int i=1;i<columns;i++) {
       txtLeaderBoard_1.append(record.toString());
       txtLeaderBoard_1.append("\n");
    }

An other approach is what the others suggested, use a different widget.

zeller
  • 4,904
  • 2
  • 22
  • 40