Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4264342

JOptionPane does not properly recognize line.separator.

XMLWordPrintable

    • beta
    • x86
    • windows_nt



      Name: wl91122 Date: 08/20/99


      When I build a text message using System.getProperty("line.separator") and then display it in a JOptionPane on Windows, a non-printable character is displayed. JOptionPane
      and possibly other GUI components should properly recognize and display System.getProperty("line.separator").

      Sample code to reproduce the problem:

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class OptionBug extends JFrame {
          boolean packFrame = false;
          JButton pressButton = new JButton();
          FlowLayout flowLayout1 = new FlowLayout();

          //Construct the application
        public OptionBug() {
              try {
                  jbInit();
              }
              catch(Exception e) {
                  e.printStackTrace();
              }
          }

          private void jbInit() throws Exception {
              pressButton.setText("Press");
              pressButton.addActionListener(new OptionBug_pressButton_actionAdapter(this));
              this.getContentPane().setLayout(flowLayout1);
              this.getContentPane().add(pressButton, null);
          }

          void pressButton_actionPerformed(ActionEvent e) {
              String terminator = System.getProperty("line.separator");
              JOptionPane.showMessageDialog(
                  this,
                  "System.getProperty(\"line.separator\")" +
                      terminator +
                      "Does not work in JOptionPane & possibly other text objects." +
                      terminator +
                      "On Windows a non-printable character appears.",
                  "JOptionPane does not recognize platform independant EOL.",
                  JOptionPane.INFORMATION_MESSAGE);
          }

          public static void main(String[] args) {
              OptionBug bug = new OptionBug();
              bug.pack();
              bug.setVisible(true);
          }
      }

      class OptionBug_pressButton_actionAdapter implements java.awt.event.ActionListener {
          OptionBug adaptee;

          OptionBug_pressButton_actionAdapter(OptionBug adaptee) {
              this.adaptee = adaptee;
          }

          public void actionPerformed(ActionEvent e) {
              adaptee.pressButton_actionPerformed(e);
          }
      }
      (Review ID: 94177)
      ======================================================================

            amfowler Anne Fowler (Inactive)
            wleesunw William Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: