Rendre un composant perso Scrollable
Bonjour,
j'ai crée un composant qui dessine une courbe.
J'ai donc crée une classe qui étend JComponent.
Je souhaite que, quand les points que je dessine sortent du composant, des scrollbar apparaîssent.
Mon composant étend la classe Scrollable est il est placé dans un JScrollpane.
Mon problème est que je ne sait pas quoi mette dans les méthode de l'interface Scrollable. J'ai regardé le code de la classe JTextComponent et j'ai recopié les méthodes concernées.
Mais toujours pas de scrollbar qui apparaîssent.
Quelqu'un pourraît m'expliquer comment faire, ou encore mieux quelqu'un aurait'il un exemple ??
Voici l'implémentation des méthodes de l'interface Scrollable
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| /* (non-Javadoc)
* @see javax.swing.Scrollable#getPreferredScrollableViewportSize()
*/
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
/* (non-Javadoc)
* @see javax.swing.Scrollable#getScrollableUnitIncrement(java.awt.Rectangle, int, int)
*/
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
switch(orientation) {
case SwingConstants.VERTICAL:
System.out.println("getScrollableUnitIncrement : " + visibleRect.height/10);
return visibleRect.height / 10;
case SwingConstants.HORIZONTAL:
System.out.println("getScrollableUnitIncrement : " + visibleRect.width/10);
return visibleRect.width / 10;
default:
throw new IllegalArgumentException("Invalid orientation: " + orientation);
}
}
/* (non-Javadoc)
* @see javax.swing.Scrollable#getScrollableBlockIncrement(java.awt.Rectangle, int, int)
*/
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
switch(orientation) {
case SwingConstants.VERTICAL:
System.out.println("getScrollableBlockIncrement : " + visibleRect.height);
return visibleRect.height;
case SwingConstants.HORIZONTAL:
System.out.println("getScrollableBlockIncrement : " + visibleRect.width);
return visibleRect.width;
default:
throw new IllegalArgumentException("Invalid orientation: " + orientation);
}
}
/* (non-Javadoc)
* @see javax.swing.Scrollable#getScrollableTracksViewportWidth()
*/
public boolean getScrollableTracksViewportWidth() {
if (getParent() instanceof JViewport) {
return (((JViewport)getParent()).getWidth() > getPreferredSize().width);
}
return false;
}
/* (non-Javadoc)
* @see javax.swing.Scrollable#getScrollableTracksViewportHeight()
*/
public boolean getScrollableTracksViewportHeight() {
if (getParent() instanceof JViewport) {
return (((JViewport)getParent()).getHeight() > getPreferredSize().height);
}
return false;
} |
C'est le code recopié du JTextComponent[/b]
HELP ME PLEASE :roll:
Cyrille