Raghav Chandra
Raghav Chandra

Reputation: 23

Scrollable Text Area?

I'm trying to figure out how do i add a scrolling bar to my frame?

I have this

private void textArea() {
    myFrame = new JFrame("Test");
    myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    myFrame.setLocationRelativeTo(null);
    myFrame.setSize(300, 300);
    myPane = new JTextPane();
    myPane.setText("Choose a File to Process");
    myFrame.setContentPane(myPane);
    JMenuBar myBar = new JMenuBar();
    JMenu myMenu = getFileMenu();
    JButton button = new JButton("Select File");
    myBar.add(myMenu);
    myBar.add(button);
    myFrame.setJMenuBar(myBar);
    myFrame.setVisible(true);
}

private JMenu getFileMenu() {
    JMenu myMenu = new JMenu("File");
    cmdOpen = new JMenuItem("Open CSV File");
    cmdOpen.addActionListener(this);
    myMenu.add(cmdOpen);
    return myMenu;
}

The output of my file is really big. Also i tried all the other solutions but i could not fix it

Upvotes: 0

Views: 40

Answers (1)

Mohammed Aouf Zouag
Mohammed Aouf Zouag

Reputation: 17132

Try this:

myFrame.setContentPane(new JScrollPane(myPane));

Upvotes: 2

Related Questions