3

I am using this code to add a scroll panel in my JFrame

JScrollPane pane = new JScrollPane(getContentPane(),
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.setContentPane(pane);

I can view the scroll-bar but it is not scrollable even after resizing the window.

Syeda Zunaira
  • 5,191
  • 3
  • 38
  • 70

2 Answers2

2

Yupii!!!!!! Got the solution of my problem. I just need to add

setPreferredSize(new Dimension(900, 900));

to my contentpane. Thanks For every one.

Syeda Zunaira
  • 5,191
  • 3
  • 38
  • 70
2

use this code it worked for me

    container.setSize(1800, 1500);
    container.setVisible(true);



    container.setPreferredSize(new Dimension(900, 900));
    JScrollPane scrollPane = new JScrollPane(container);  
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);  
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);  

    add(scrollPane);