• Post Reply Bookmark Topic Watch Topic
  • New Topic

2nd call urgent please help

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!