How to center scrollbars?

J

jcd.news

Hello.
I would like to know how to center scrollbars:
I created a JScrollPane called panneauVueDuHaut (in french).
I added panneauDessinVueDuHaut to this JScrollPane which is an
instance of the class ClassePanneauVueDuHaut which extends JPanel.
I overrode the paint method:


public void paint(Graphics g) {
if(img==null) { //img is an instance of Image
img=createImage(Xmax,Ymax);
bg=img.getGraphics();

}
Graphics2D g2=(Graphics2D) bg;
g2.setColor(Color.white);
g2.fillRect(0,0,Xmax,Ymax);
g2.drawline........
..........
g.drawImage(img,0,0,this);



Is it well built to be as fast as possible?
When panneauDessinVueDuHaut is first displayed, I would like the
scrollbars to be centered on the Image img (the size of img is
(Xmax,Ymax)).
How I can I do or where can I find a website about this?
thank you.
 
K

Knute Johnson

Hello.
I would like to know how to center scrollbars:
I created a JScrollPane called panneauVueDuHaut (in french).
I added panneauDessinVueDuHaut to this JScrollPane which is an
instance of the class ClassePanneauVueDuHaut which extends JPanel.
I overrode the paint method:


public void paint(Graphics g) {
if(img==null) { //img is an instance of Image
img=createImage(Xmax,Ymax);
bg=img.getGraphics();

}
Graphics2D g2=(Graphics2D) bg;
g2.setColor(Color.white);
g2.fillRect(0,0,Xmax,Ymax);
g2.drawline........
..........
g.drawImage(img,0,0,this);



Is it well built to be as fast as possible?
When panneauDessinVueDuHaut is first displayed, I would like the
scrollbars to be centered on the Image img (the size of img is
(Xmax,Ymax)).
How I can I do or where can I find a website about this?
thank you.

From the JScrollPane you can get the JViewPort. It has methods to
adjust itself.
 
J

Jeff Higgins

jcd.news said:
Hello.
I would like to know how to center scrollbars:
I created a JScrollPane called panneauVueDuHaut (in french).
I added panneauDessinVueDuHaut to this JScrollPane which is an
instance of the class ClassePanneauVueDuHaut which extends JPanel.
I overrode the paint method:


public void paint(Graphics g) {
if(img==null) { //img is an instance of Image
img=createImage(Xmax,Ymax);
bg=img.getGraphics();

}
Graphics2D g2=(Graphics2D) bg;
g2.setColor(Color.white);
g2.fillRect(0,0,Xmax,Ymax);
g2.drawline........
..........
g.drawImage(img,0,0,this);



Is it well built to be as fast as possible?
When panneauDessinVueDuHaut is first displayed, I would like the
scrollbars to be centered on the Image img (the size of img is
(Xmax,Ymax)).
How I can I do or where can I find a website about this?

Knute mentions the JViewport class.
Another option might be the Scrollable interface.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top