user1524153
user1524153

Reputation: 1

Formatting Text

I need to format some text in JOptionPane.showMessageDialog. I need the text to be in tabular format Example:

Operation           Result
  2 + 2               4

I have tried to use string.format() but it comes out ugly. Any suggestions would be helpful. Thanks

Upvotes: 0

Views: 108

Answers (3)

PeakGen
PeakGen

Reputation: 22995

It seems like you got some number of data to be displayed. Using JDialog instead of JOptionpane is better to put number of data. Answer to your question can be found in the below link

http://forums.techguy.org/software-development/1051819-solved-help-java-tabular-format.html

Upvotes: 1

Adam
Adam

Reputation: 17329

String.format would work well if you were using a fixed-width font (like a console output) but the message dialogs default to a variable-width font.

Luckily all labels in Swing support HTML formatting. All you have to do is wrap your string with HTML tags like <html> some text</html>. Then you could use an actual HTML table.

Upvotes: 1

Zsolt J&#225;nos
Zsolt J&#225;nos

Reputation: 511

You can pass a String containing the data in html code, you can try to do this format with a HTML table.

Upvotes: 0

Related Questions