0

For some reason, JOptionPane.showOptionDialog does not accept \n on runtime. It aknowledges it by not displaying "\n" or giving any errors but it also does not create a new line for the text. I cannot use a text block as it is stored to an array. I don't understand how it happened but this is a very strange bug. To my knowledge, "\n" creates a new line that any text afterwards will be outputted there.

int intReportOption = 0;
String[] strReportOptions =
   {
      "Show tasks\nthat are done",
      "Show longest\ntask",
      "Search for task\nby task name",
      "Search for task by\nassigned person",
      "Delete\ntask",
      "Show\nreport",
      "Exit"
   };
      while (intReportOption != 6)
   {
      intReportOption = JOptionPane.showOptionDialog(null,
      "Pick an option",
      "EasyKanban",
      JOptionPane.DEFAULT_OPTION,
      JOptionPane.QUESTION_MESSAGE,
      null,
      strReportOptions,
      strReportOptions[0]);
}

Most searches on google say to use "\n" with some giving html syntax(for java?) which means my problem is special or stupid. Any help/suggestions would be greatly appreciated.

Dharvish
  • 1
  • 4
  • 4
    easy way (not necessarily the best): use (pseudo-)html [How to Use HTML in Swing Components](https://docs.oracle.com/javase/tutorial/uiswing/components/html.html) (e.g. `"Show longest
    task"`) | also [How to add a multi line text to a JButton with the line unknown? (dynamically)](https://stackoverflow.com/questions/15746970/how-to-add-a-multi-line-text-to-a-jbutton-with-the-line-unknown-dynamically)
    – user16320675 Jun 16 '23 at 16:07
  • @user16320675 Just checked with my lecturer and he says that using html in java will be fine as long as I use JOption. Many thanks! – Dharvish Jun 19 '23 at 09:15

0 Answers0