• Post Reply Bookmark Topic Watch Topic
  • New Topic

why isnt this working urgent please help  RSS feed

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why isnt this working im trying to connect a panel to a scrollpane the panel will contain several dozen text fields
the scrollpane shouls be about 350, 450 , but the pane is 350
by 1200 the problem now is that the scorllbar isnt created and even when I explictly create it it contains no knob, and it will
not scroll up or down please someone help this is urgent
import java.awt.*;
import com.sun.java.swing.*;
public class ScrollDemo extends JPanel {
private Rule columnView;
private Rule rowView;
private ScrollablePicture picture;
class UnitsListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
// Turn it to metric.
rowView.setIsMetric(true);
columnView.setIsMetric(true);
} else {
// Turn it to inches.
rowView.setIsMetric(false);
columnView.setIsMetric(false);
}
picture.setMaxUnitIncrement(rowView.getIncrement());
}
}
public ScrollDemo() {
Two t = new Two(columnView.getIncrement());
JScrollPane pictureScrollPane = new JScrollPane(t);
pictureScrollPane.setPreferredSize(new Dimension(300, 250));
pictureScrollPane.setColumnHeaderView(columnView);
pictureScrollPane.setRowHeaderView(rowView);
}
public static void main(String s[]) {
JFrame frame = new JFrame("ScrollDemo");
frame.setContentPane(new ScrollDemo());
frame.setVisible(true);
}
import java.awt.*;
import com.sun.java.swing.*;
public class Two extends JPanel implements Scrollable{
private JPanel ivjJPanel3 = null;
private JScrollPane ivjJScrollPane1 = null;
private int maxUnitIncrement = 1;
public Two(int m)
{
getJPanel1();
maxUnitIncrement = m;
setSize(300,1200);
}

private void getJPanel1() {
setLayout(null);
setSize(250,1200);
add(getJLabel1(), getJLabel1().getName());
}
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;
//Return the number of pixels between currentPosition
//and the nearest tick mark in the indicated direction.
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;
}

 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other than it being ugly looking code. Where are you adding a JScrollPane to the JFrame?
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Stevens:
Other than it being ugly looking code. Where are you adding a JScrollPane to the JFrame?

I obtained the from a textBook and it used a Jlabel with
an Icon and that works i simply changed the JLabel to
JPanel.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!