aspose file tools
The moose likes Swing / AWT / SWT and the fly likes JScrollPane doesn't work? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "JScrollPane doesn Watch "JScrollPane doesn New topic
Author

JScrollPane doesn't work?

Con Lu
Ranch Hand

Joined: Aug 27, 2002
Posts: 38
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,
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Try setPreferredSize( new Dimension (600,400 ) ); in the constructor of the P1 panel and it will work...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JScrollPane doesn't work?
 
Similar Threads
How tp detach a Frame from the Main Application ?
JTextArea image
Haw to separate a frame to diferent fraims
getting a JScrollPane to display its scrollbars
more tabbedpane - panel questions