How to add a multi line text to a JButton with the line unknown? (dynamically)
html, java, jbutton, multiline, swing
Solution
You'll need to at least know how each line is delimited. For example if lines are delimited with newline characters, you could do:
String twoLines = "Two\nLines";
JButton b =
new JButton("<html>" + twoLines.replaceAll("\\n", "<br>") + "</html>");
Problem
How do you make the text on a `JButton` multiline? I have read that most use HTML, but what happens when it is dynamic and you don't know the size of the lines, or what the lines are? Right now the text on my button just ends with `...` as opposed to making a new line. Most other methods assume you know the string and are hard coded, so you can't do this on the fly. Edited: I created a method that will do this dynamically for a button