Can't get my Jscrollpane working in my Jtextarea

Posted by Bobski on Stack Overflow See other posts from Stack Overflow or by Bobski
Published on 2013-11-09T15:17:58Z Indexed on 2013/11/09 15:54 UTC
Read the original article Hit count: 176

Filed under:
|
|
|

I've looked around quite a lot on google and followed several examples however I can't seem to get my JScrollPane working on a textarea in a JPanel.

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

class main
{
    public static void main(String Args[])
    {
    frame f1 = new frame();
    }
}

class frame extends JFrame      
{

    JButton B = new JButton("B");   
    JButton button = new JButton("A");  
    JTextArea E = new JTextArea("some lines", 10, 20);
    JScrollPane scrollBar = new JScrollPane(E);
    JPanel grid = new JPanel ();        

    frame()
    {


    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500,800);
    setTitle("Mobile Phone App");
    setLocationRelativeTo(null);        

    E.setLineWrap(true);
    E.setEditable(false);

     grid.add(button);
     button.addActionListener(new action());

    grid.add(B);
    B.addActionListener(new action());

    //grid.add(E);
    grid.getContentPane().add(scrollBar);
    add(grid);              



    setVisible(true);
    }
    class action implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            String V = E.getText();

            if(e.getSource() == button)
            {
                E.setText(V + "A is pressed");
            }
            if(e.getSource() == B)
            {
                E.setText(V + "B is pressed");
            }
        }
    }

}

Would be great if someone can see where I am going wrong. I added JscrollPane in which I added the text area "e" in it.

© Stack Overflow or respective owner

Related posts about java

Related posts about swing