Results 1 to 8 of 8
  1. #1
    kumar.dinesh7 is offline Member
    Join Date
    May 2012
    Location
    Yamuna Nagar,Haryana,India
    Posts
    28
    Rep Power
    0

    Default poblem in making textarea scrollable over JPanel

    i am using JPanel with null layout.....
    put a textarea on it but it is not scrolling.....


    plz help me.....

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: poblem in making textarea scrollable over JPanel

    You need to wrap your textarea in a JScrollPane component. This will add scrolling capability to the textarea.

  3. #3
    kumar.dinesh7 is offline Member
    Join Date
    May 2012
    Location
    Yamuna Nagar,Haryana,India
    Posts
    28
    Rep Power
    0

    Default Re: poblem in making textarea scrollable over JPanel

    i already wrap the textarea in JScrollPane component...but still its not working

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: poblem in making textarea scrollable over JPanel

    Can you post the section of your program that related how you create a text area and place it inside a scroll pane?

  5. #5
    kumar.dinesh7 is offline Member
    Join Date
    May 2012
    Location
    Yamuna Nagar,Haryana,India
    Posts
    28
    Rep Power
    0

    Default Re: poblem in making textarea scrollable over JPanel

    this is the code......i uses a different class for making textarea scrollable



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





    class text extends JFrame implements KeyListener
    {
    JPanel jp;
    boolean txtChanged = false;
    JTextArea t;
    File file;
    String fname = "";
    String buf="";
    Container c;
    text()
    {
    setUndecorated(true);
    setVisible(true);
    setResizable(true);
    setLocation(550,100);
    setSize(600,650);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    ImageIcon img = new ImageIcon("icon.png");
    setIconImage(img.getImage());
    jp=new JPanel();
    jp.setLayout(null);
    t=new JTextArea();
    JScrollPane scroll= new JScrollPane(t);
    t.setBorder(BorderFactory.createLineBorder(Color.b lack));
    t.setFocusable(true);
    //t.setEditable(false);
    scroll.setVisible(true);
    c = getContentPane();
    c.setLayout(new BorderLayout());
    //add(jp);
    c.add(scroll, BorderLayout.CENTER);
    t.addKeyListener(this);
    try
    {
    FileReader fr=new FileReader("intro.txt");
    BufferedReader br=new BufferedReader(fr);
    while ((buf=br.readLine()) != null)
    {
    t.append(buf);
    t.append("\n");
    }
    br.close();
    fr.close();
    }
    catch (IOException evt)
    {
    System.out.println("Exception: " + evt);
    }
    }


    public void keyPressed(KeyEvent e)
    {
    //System.out.println("KP");
    }

    public void keyReleased(KeyEvent e)
    {
    //System.out.println("KR");
    }
    public void keyTyped(KeyEvent ke)
    {
    txtChanged = true;
    }
    }














    public class array extends JFrame implements ActionListener
    {
    JPanel jp;
    static JButton basic,operation,user_practice,menu;
    JLabel bg,logo;
    array()
    {
    super("Array-Data Structure Tutorial");
    setVisible(true);
    setResizable(true);
    setLocation(0,0);
    setSize(1200,780);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    ImageIcon img = new ImageIcon("icon.png");
    setIconImage(img.getImage());
    jp=new JPanel();
    jp.setBounds(0,0,500,800);
    jp.setLayout(null);
    basic=new JButton("Basic Terminology",new ImageIcon("basic.jpg"));
    operation=new JButton("Operations",new ImageIcon("operation.jpg"));
    menu=new JButton("",new ImageIcon("home.png"));
    user_practice=new JButton("User Practice",new ImageIcon("user.jpg"));
    bg=new JLabel(new ImageIcon("bg1.jpg"));
    logo=new JLabel(new ImageIcon("logo.png"));
    Font f2=new Font("calibri",Font.PLAIN,20);
    Font f3=new Font("Times New Roman",Font.BOLD,15);
    basic.setFont(f2);
    operation.setFont(f2);
    user_practice.setFont(f2);
    menu.setFont(f2);
    add(jp);
    jp.add(basic);
    jp.add(operation);
    jp.add(user_practice);
    jp.add(menu);
    jp.add(bg);
    bg.add(logo);
    basic.addActionListener(this);
    operation.addActionListener(this);
    user_practice.addActionListener(this);
    menu.addActionListener(this);
    basic.setBounds(100,160,250,60);
    operation.setBounds(100,260,250,60);
    user_practice.setBounds(100,560,250,60);
    menu.setBounds(55,30,50,50);
    bg.setBounds(0,0,1300,800);
    logo.setBounds(700,1,850,80);
    text t=new text();
    }


    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==menu)
    {
    main m1=new main();
    this.setVisible(false);
    }
    else if(e.getSource()==basic)
    {
    basicarray m1=new basicarray();
    this.setVisible(false);

    }
    else if(e.getSource()==operation)
    {
    operations m2=new operations();
    this.setVisible(false);
    }

    else if(e.getSource()==user_practice)
    {
    practicearray m4=new practicearray();
    this.setVisible(false);
    }

    }

    }

  6. #6
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: poblem in making textarea scrollable over JPanel

    Please format your code to make it easier to read, use the [code] tag for this.

    By default when the text area have no data or if the data is visible without scrolling the scroll bar will not be displayed. If you want to change this default you can use the other JScrollPane constructor that accept the vertical and horizontal scrollbar policy.

  7. #7
    kumar.dinesh7 is offline Member
    Join Date
    May 2012
    Location
    Yamuna Nagar,Haryana,India
    Posts
    28
    Rep Power
    0

    Default Re: poblem in making textarea scrollable over JPanel

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    
    
    
    
    
    class text extends JFrame implements KeyListener
    {
    JPanel jp;
    boolean txtChanged = false;
    JTextArea t;
    File file;
    String fname = "";
    String buf="";
    Container c;
    text()
    {
    setUndecorated(true);
    setVisible(true);
    setResizable(true);
    setLocation(550,100);
    setSize(600,650);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    ImageIcon img = new ImageIcon("icon.png");
    setIconImage(img.getImage());
    jp=new JPanel();
    jp.setLayout(null);
    t=new JTextArea();
    JScrollPane scroll= new JScrollPane(t);
    t.setBorder(BorderFactory.createLineBorder(Color.b lack));
    t.setFocusable(true);
    //t.setEditable(false);
    scroll.setVisible(true);
    c = getContentPane();
    c.setLayout(new BorderLayout());
    //add(jp);
    c.add(scroll, BorderLayout.CENTER);
    t.addKeyListener(this);
    try
    {
    FileReader fr=new FileReader("intro.txt");
    BufferedReader br=new BufferedReader(fr);
    while ((buf=br.readLine()) != null)
    {
    t.append(buf);
    t.append("\n");
    }
    br.close();
    fr.close();
    }
    catch (IOException evt)
    {
    System.out.println("Exception: " + evt);
    }
    }
    
    
    public void keyPressed(KeyEvent e)
    {
    //System.out.println("KP");
    }
    
    public void keyReleased(KeyEvent e)
    {
    //System.out.println("KR");
    }
    public void keyTyped(KeyEvent ke)
    {
    txtChanged = true;
    }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public class array extends JFrame implements ActionListener
    {
    JPanel jp;
    static JButton basic,operation,user_practice,menu;
    JLabel bg,logo;
    array()
    {
    super("Array-Data Structure Tutorial");
    setVisible(true);
    setResizable(true);
    setLocation(0,0);
    setSize(1200,780);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    ImageIcon img = new ImageIcon("icon.png");
    setIconImage(img.getImage());
    jp=new JPanel();
    jp.setBounds(0,0,500,800);
    jp.setLayout(null);
    basic=new JButton("Basic Terminology",new ImageIcon("basic.jpg"));
    operation=new JButton("Operations",new ImageIcon("operation.jpg"));
    menu=new JButton("",new ImageIcon("home.png"));
    user_practice=new JButton("User Practice",new ImageIcon("user.jpg"));
    bg=new JLabel(new ImageIcon("bg1.jpg"));
    logo=new JLabel(new ImageIcon("logo.png"));
    Font f2=new Font("calibri",Font.PLAIN,20);
    Font f3=new Font("Times New Roman",Font.BOLD,15);
    basic.setFont(f2);
    operation.setFont(f2);
    user_practice.setFont(f2);
    menu.setFont(f2);
    add(jp);
    jp.add(basic);
    jp.add(operation);
    jp.add(user_practice);
    jp.add(menu);
    jp.add(bg);
    bg.add(logo);
    basic.addActionListener(this);
    operation.addActionListener(this);
    user_practice.addActionListener(this);
    menu.addActionListener(this);
    basic.setBounds(100,160,250,60);
    operation.setBounds(100,260,250,60);
    user_practice.setBounds(100,560,250,60);
    menu.setBounds(55,30,50,50);
    bg.setBounds(0,0,1300,800);
    logo.setBounds(700,1,850,80);
    text t=new text();
    }
    
    
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==menu)
    {
    main m1=new main();
    this.setVisible(false);
    }
    else if(e.getSource()==basic)
    {
    basicarray m1=new basicarray();
    this.setVisible(false);
    
    }
    else if(e.getSource()==operation)
    {
    operations m2=new operations();
    this.setVisible(false);
    }
    
    else if(e.getSource()==user_practice)
    {
    practicearray m4=new practicearray();
    this.setVisible(false);
    }
    
    }
    
    }

  8. #8
    kumar.dinesh7 is offline Member
    Join Date
    May 2012
    Location
    Yamuna Nagar,Haryana,India
    Posts
    28
    Rep Power
    0

    Default Re: poblem in making textarea scrollable over JPanel

    okay thanx......can u tell me how to control the one form by another form...
    like in the above code if i minimize the form then that textarea will also be minimized...

    plz run the above code to understand what i am saying..

Similar Threads

  1. Replies: 7
    Last Post: 03-16-2012, 06:24 PM
  2. Making my JComponent scrollable
    By kjkrum in forum AWT / Swing
    Replies: 4
    Last Post: 03-11-2012, 08:08 PM
  3. Replies: 1
    Last Post: 03-03-2012, 09:35 PM
  4. Help making calculator with TextArea
    By matrixcool in forum AWT / Swing
    Replies: 9
    Last Post: 12-15-2010, 02:56 AM
  5. Can't resize textarea in JPanel Form
    By wiguy in forum NetBeans
    Replies: 0
    Last Post: 04-02-2009, 10:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •