Java 摆动中的对象数组
所以我得到了一组对象 我现在要显示它们的代码在一个JLabel中,如下所示Java 摆动中的对象数组,java,swing,jlabel,Java,Swing,Jlabel,所以我得到了一组对象 我现在要显示它们的代码在一个JLabel中,如下所示 public void setLblEvents(Calendar[] calendars) { String result = ""; for(int i = 0; i< calendars.length; i++) { result += (+i +calendars[i].getTitle()); result += (+i +calendars[i].getStartDat
public void setLblEvents(Calendar[] calendars) {
String result = "";
for(int i = 0; i< calendars.length; i++)
{
result += (+i +calendars[i].getTitle());
result += (+i +calendars[i].getStartDate());
result += (+i +calendars[i].getEndDate());
result += (+i +calendars[i].getNote());
result += (+i +calendars[i].getLocation());
}
lblEvents.setText(result);
}
这将在我的jlabel中的一行文本中输出所有标题、所有起始日期等
如何以最简单的方式以漂亮的方式显示它。要以多行显示标签上的文本,您需要执行以下操作:
String result = "<html>";
for(int i = 0; i< calendars.length; i++){
result += (+i +calendars[i].getTitle()+"<br>");
result += (+i +calendars[i].getStartDate()+"<br>");
result += (+i +calendars[i].getEndDate()+"<br>");
result += (+i +calendars[i].getNote()+"<br>");
result += (+i +calendars[i].getLocation());
}
result += "</html>"
lblEvents.setText(result);
添加\n需要换行符的位置?将JList与适当的渲染器结合使用?使用HTML?这取决于你以后想用它做什么。我会使用JTable。有关更多信息和示例,请阅读上Swing教程的部分。