| 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.
|
 |
 |
|
|
subject: JScrollPane doesn't work?
|
|
|