2

I was putting simple loading animation to my previous code but I can't fine a way to begin new line when its showing the result.

JFrame frame = new JFrame("Max");

ImageIcon loading = new ImageIcon("ajax-loader.gif");
frame.add(new JLabel("Processing to Result \n Result of Maximum is : "+max, loading,
                                                                       JLabel.CENTER));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.setVisible(true);

enter image description here

I also try to use newline and %n but both does not work.

Kashama Shinn
  • 241
  • 2
  • 4
  • 11

2 Answers2

4

There is no easy way to add new line to JLabel without HTML tags.

You should do something like that:

frame.add(new JLabel("<html>Processing to Result <br> Result of Maximum is :" + max + 
           "</html>", loading,JLabel.CENTER));

If you want, you can switch to SwingX, it does support that without HTML tags :)

Maroun
  • 94,125
  • 30
  • 188
  • 241
  • Thank it work now. one more thing, do you know how to make it a better look? like: Loading animation showing 5sec then showing the result. Very appreciate for you answer. Thank again. – Kashama Shinn Sep 01 '13 at 08:18
2

A JLabel by default does not do any formatting. However you can use simply HTML tags to achieve what you want:

String label = "<html>Processing to Result<br>Result of Maximum is : "+max + "</html>;
frame.add(new JLabel(label, loading, JLabel.CENTER));
  • Thank it work now. one more thing, do you know how to make it a better look? like: Loading animation showing 5sec then showing the result. Very appreciate for you answer. Thank again. – Kashama Shinn Sep 01 '13 at 08:19