I have a list that contains String
s and I am trying to set its items as JLabel
text, the only problem is that the result is a single line
JButton btnSearch = new JButton("Search");
btnSearch.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
String fileName = textField.getText();
StringBuilder result = new StringBuilder();
List <String> searchResult = new Search().cautaFisiere("C:\\AdwCleaner", fileName);
for (int x = 0; x < searchResult.size(); x++) {
result.append(searchResult.get(x)).append("\n");
}
lblNewLabel.setText(result.toString());
}
});
As you can see I tried appending items as new line but no result. I also tried append(System.getProperty("line.separator"))
but still no result, the text is still displayed in one line
As mentioned in here Multiline text in JLabel , just can just use HTML tag <br>
to make a new line, but it must be in <html></html>
tags.
JButton btnSearch = new JButton("Search");
btnSearch.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
String fileName = textField.getText();
StringBuilder result = new StringBuilder();
List <String> searchResult = new Search().cautaFisiere("C:\\AdwCleaner", fileName);
for (int x = 0; x < searchResult.size(); x++) {
result.append(searchResult.get(x)).append("<br>");
}
lblNewLabel.setText("<html>" + result.toString() + "</html>");
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.