• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JScrollPane doesn't work?

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gidday,
I have done the following:-
1) Created a JFrame
2) Created a JScrollPane
3) Added a large panel to the JScrollPane
4) Added the JScrollPane to the JFrame
The scrollbars appear but don't scroll to see the
large panel. The code is below:-
import javax.swing.*;
import java.awt.*;
public class Trial1{
public static void main(String args[]){
JFrame f1 = new JFrame();
f1.setTitle("Trial1");
JScrollPane sP = new JScrollPane(new P1(), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
sP.setPreferredSize(new Dimension(300,200));
f1.getContentPane().add(sP);
f1.setBounds(25,25,400,300);
f1.setVisible(true);
}
}
class P1 extends JPanel{
P1(){
setSize(600,400);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.fillRect(25,25,500,350);
}
}
Any help would be much appreciated,
Thanks,
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try setPreferredSize( new Dimension (600,400 ) ); in the constructor of the P1 panel and it will work...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic