Wednesday, June 21, 2017

[Solved] How to make a JOptionPane scrollable?

Here are  the steps for making a JOptionPane scrollable.

1. Create a JTextArea with fixed rows and columns to hold your text information.

      String message = <my long message to display>

      JTextArea textArea = new JTextArea(messate, <rows>,  <columns>);
     
      It is very critical to set the rows and columns. They determine the size of the view in the JOptionPane.

2. Create a JScrollPane which has the JTextArea as the view port.

      JScrollPane sp = new JScrollPane(textArea);
      sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

3. Create the JOptionPane using the JScrollPane as its displaying component

      JOptionPane.showMessageDialog(null, sp);

---------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.
     

No comments:

Post a Comment