tags:

views:

100

answers:

1

I need to have a long descriptive dialog in part of my program and it display differently in mac and windows. On the mac in seems to word wraps the text and breaks it down into 3 or 4 lines but on the PC it just creates a really long dialog. Here is some code that shows my problems:

public class Test extends JFrame{

import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Test extends JFrame{
private String suggestion = "eee eee eeee eeee eeeerr rrrrr rrrrrrrr rrrrrr " +
        "rrrrrr rrrrrrrrr  rrrrrr rrrrr tttttt ttttttttttt ttttt tttttttttt ttt" +
        " tttt tttttt ttttttttttt reroew uewurkpe jwrkl;ejr kejk ejrk;jewr;jeklr " +
        "jk jre;wlj;ewjr;ej lejrlkejlkejlkjerl  ejlrj kleklr jekl jlek " +
        "rjklejrklejrklekl ";
public void showDialog()
{
           JOptionPane.showMessageDialog(this,
                                  suggestion,
                                  "title",
                                  JOptionPane.INFORMATION_MESSAGE,
                                  null);
}
public static void main(String [] args)
{
    Test test = new Test();
    test.showDialog();
}
}

when I run this on Windows it just created one huge line of text in a long dialog but on the mac it creates multiple lines with a properly sized dialog.

+3  A: 

The JOptionPane component has a read-only property (MaxCharactersPerLineCount) for the maximum number of characters per line. By default, this is Integer.MAX_VALUE. By subclassing JOptionPane, you can override this setting. Changing this setting allows the component to word-wrap when a message is really long.

http://java.sun.com/developer/JDCTechTips/2004/tt0122.html

Stefan Kendall
It's interesting how it is different on the mac vs pc though
hhafez
Swing will do that between mac and windows/linux. I had so much hell in a previous project getting things to work correctly on mac, especially with regard to text display. I'm not surprised it works differently.
Stefan Kendall
Worked like a charm thanks!
Mike2012