我正在尝试使用多行文本制作 Swing JLabel。它添加得很好,但换行符没有通过。我该怎么做呢?或者,我可以只为 JLabel 指定最大宽度并知道文本会换行吗,就像在 div 中一样?
private void addLegend() {
JPanel comparisonPanel = getComparisonPanel();
//this all displays on one line
JLabel legend = new JLabel("MMM FFF MMM FFFO O OOM M MMMM.\nMMM FFF MMM FFFO O OOM M MMMM.\nMMM FFF MMM FFFO O OOM M MMMM.\n");
comparisonPanel.add(legend);
}