Re: Tab character in JOptionPane?
On Mar 24, 1:57 pm, BL <u...@example.com> wrote:
Is it possible to insert a tab character into a JOptionPane? It seems to
just ignore it when I use "\t".
It comes down to the abilities of the
JComponent used to render the String.
E.G.
<sscce>
import java.awt.*;
import javax.swing.*;
public class TabsInMessage {
public static void main(String[] args) {
String tabString = "a\tb";
JOptionPane.showMessageDialog( null,
tabString,
"String (becomes JLabel)",
JOptionPane.INFORMATION_MESSAGE );
JOptionPane.showMessageDialog( null,
new JLabel(tabString),
"JLabel",
JOptionPane.INFORMATION_MESSAGE );
JOptionPane.showMessageDialog( null,
new TextField(tabString),
"TextField",
JOptionPane.INFORMATION_MESSAGE );
JOptionPane.showMessageDialog( null,
new TextArea(tabString, 2, 20),
"TextArea",
JOptionPane.INFORMATION_MESSAGE );
}
}
</sscce>
...only the text area will render tabs as tabs.
Note that HTML formatting could be used to
provide PREformatted text, or an HTML table
that separates/organises output.
HTH
Andrew T.