I have a program below where I am selecting a file and displaying the content using a JTextArea. It works fine, but when I add a JScroller, it does not display the area with the scroller. What am I doing wrong?

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

public class ChooseFileAndDisplay extends JPanel implements ActionListener{
    private JButton button;
    private JPanel panel;
    private static JFrame f;
    private JTextArea area = new JTextArea();
    private JScrollPane scroller;
    public ChooseFileAndDisplay(){
        button = new JButton ("Click me");
        button.setPreferredSize(new Dimension(100, 50));
        scroller = new JScrollPane(area);
        JScrollPane scrollPane = new JScrollPane(area);
        add (button);

    public void actionPerformed (ActionEvent e){
        JFileChooser choose = new JFileChooser();
        File f = choose.getSelectedFile();
        String filepath =f.getAbsolutePath();
            FileReader reader = new FileReader(filepath);
            BufferedReader br = new BufferedReader(reader);
            area.read(br, null);
        catch (Exception E){
            JOptionPane.showMessageDialog (null, E);

    public static void main (String args[]) {
        ChooseFileAndDisplay P = new ChooseFileAndDisplay();
        f = new JFrame ("Picture Grid");
        f.setSize(800, 800);
        f.setVisible (true);

Recommended Answers

I'm guessing you meant this example and scroller at https://www.jque.re/plugins/scrollbars-onscroll/jscroller/index.html

In example 4 there, the scroll bars do hide when the mouse is not on the image.

Jump to Post

All 2 Replies

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.