IntelliJ Java IDE
The moose likes Swing / AWT / SWT / JFace and the fly likes 2nd call urgent please help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "2nd call urgent please help" Watch "2nd call urgent please help" New topic
Author

2nd call urgent please help

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 329
i think this will make things more clear. Im trying to add a
JPanel with several dozen Jtextfields, (JPanel size 350,1200)
and Im trying to add this to a JScrollPane. MY PROBLEM the
scrollPane is not showing a vertical ScrollBar. When I tell it to
show a scrollBar, it appears, but their is no knob and the scrollbar when pressed does not affect the Jpanel( ie the panel does not go up or down)
Please can someone help this is urgent.
public ScrollDemo()
{
Two t = new Two(1);
JScrollPane pictureScrollPane = new JScrollPane(t);
pictureScrollPane.setPreferredSize(new Dimension(300, 250));
}
public static void main(String s[])
{
JFrame frame = new JFrame();
frame.setContentPane(new ScrollDemo());
frame.setVisible(true);
}
public class Two extends JPanel implements Scrollable{
private JPanel JPanel3 = null;
private JScrollPane JScrollPane1 = null;
private int maxUnitIncrement = 1;
public Two(int m)
{
getJPanel1();
maxUnitIncrement = m;
setSize(300,1200);
}
private void getJPanel1()
{
setLayout(null);
add(getJLabel1());
}
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation,int direction) {
if (orientation == SwingConstants.HORIZONTAL)
return visibleRect.width - maxUnitIncrement;
else
return visibleRect.height - maxUnitIncrement;
}
public boolean getScrollableTracksViewportHeight() {
return false;
}
public boolean getScrollableTracksViewportWidth() {
return false;
}
public int getScrollableUnitIncrement(Rectangle visibleRect,
int orientation,int direction) {
//Get the current position.
int currentPosition = 0;
if (orientation == SwingConstants.HORIZONTAL)
currentPosition = visibleRect.x;
else
currentPosition = visibleRect.y;
if (direction < 0)
{
int newPosition = currentPosition - (currentPosition / maxUnitIncrement) * maxUnitIncrement;
return (newPosition == 0) ? maxUnitIncrement : newPosition;
}
else {
return ((currentPosition / maxUnitIncrement) + 1) *
maxUnitIncrement - currentPosition;
}
}
public void setMaxUnitIncrement(int pixels) {
maxUnitIncrement = pixels;
}

Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Posts: 15040


This is some code I created to scroll a JPanel which is actually laying on top of another JPanel that is the contentPane for my internalFrame. IT works.


------------------
Happy Coding,
Gregg Bolinger


My Blog | DZone Articles
 
 
subject: 2nd call urgent please help
 
Threads others viewed
Wanted: Java2D example of zooming and panning with scroll bars
Need to insert a vertical line in Swing - Very Urgent and important
why isnt this working urgent please help
Freezing first column(JTree) in JTreeTable - Urgent Please
JTable AUTO_RESIZE_OFF and extra column
developer file tools