如何使 JTable 在一行中显示多行。

huangapple go评论49阅读模式
英文:

how can I get jtable to show multiple lines in a row

问题

and i would like my data to show like this:
MySql table
but i only get this:
java

I used this query:
GROUP_CONCAT(a.montant, a.type_avance, a.date_avance, a.remark SEPARATOR '\n') as Avance

and it works just fine in MySql but it doesn't work in jframe.

this my java code:

//declaring the table
tb_imp_pr = new JTable();
tb_imp_pr.setRowHeight(50);
tb_imp_pr.setBackground(Color.WHITE);
scrollPane.setViewportView(tb_imp_pr);
// filling the table
public void filltable_pr() {
    try {
        connectore.statement = connectore.connection.prepareStatement("SELECT i.*, GROUP_CONCAT(a.montant, a.type_avance, a.date_avance, a.remark SEPARATOR '\n') as Avance FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = a.n_dossier GROUP by i.n_dossier, i.date_dossier");
        connectore.resultSet = connectore.statement.executeQuery();
        tb_imp_pr.setModel(DbUtils.resultSetToTableModel(connectore.resultSet));
    } catch (Exception ex) {
        System.out.println();
    }
}
英文:

and i would like my data to show like this:
MySql table
but i only get this:
java

I used this query:
GROUP_CONCAT(a.montant, a.type_avance,a.date_avance,a.remark SEPARATOR '\n') as Avance

and it works just fine in MySql but it doesn't work in jframe.

this my java code:

//declaring the table
tb_imp_pr = new JTable();
		tb_imp_pr.setRowHeight(50);
		tb_imp_pr.setBackground(Color.WHITE);
		scrollPane.setViewportView(tb_imp_pr);
// filling the table
public void filltable_pr() {
		try {
			connectore.statement = connectore.connection.prepareStatement("SELECT i.*,GROUP_CONCAT(a.montant,"
+" a.type_avance,a.date_avance,a.remark SEPARATOR '\n') as Avance "
+" FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = a.n_dossier GROUP by i.n_dossier,i.date_dossier");
			connectore.resultSet = connectore.statement.executeQuery();
			tb_imp_pr.setModel(DbUtils.resultSetToTableModel(connectore.resultSet));
		} catch (Exception ex) {
			System.out.println();
			}
		
	}

答案1

得分: 0

感谢 @camickr
我知道我需要使用 "br" 并在 "br" 前后添加文本。

public void filltable_pr() {
try {
connectore.statement = connectore.connection.prepareStatement("SELECT i.*,GROUP_CONCAT('<html>',a.montant," 
+" a.type_avance,a.date_avance,a.remark SEPARATOR '<br></html>') as Avance "
+" FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = a.n_dossier GROUP by i.n_dossier,i.date_dossier");
connectore.resultSet = connectore.statement.executeQuery();
tb_imp_pr.setModel(DbUtils.resultSetToTableModel(connectore.resultSet));
} catch (Exception ex) {
   System.out.println(ex);
   }     
}
英文:

thanks to @camickr
i know that i need to use "br" and have text before and after the "br"

public void filltable_pr() {
try {
connectore.statement = connectore.connection.prepareStatement(&quot;SELECT i.*,GROUP_CONCAT(&#39;&lt;html&gt;&#39;,a.montant,&quot;
+&quot; a.type_avance,a.date_avance,a.remark SEPARATOR &#39;&lt;br&gt;&lt;/html&gt;&#39;) as Avance &quot;
+&quot; FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = a.n_dossier GROUP by i.n_dossier,i.date_dossier&quot;);
connectore.resultSet = connectore.statement.executeQuery();
tb_imp_pr.setModel(DbUtils.resultSetToTableModel(connectore.resultSet));
} catch (Exception ex) {
   System.out.println(ex);
   }     
}

huangapple
  • 本文由 发表于 2023年2月14日 18:49:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75446763.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定