Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2004

Tip: Looking for answers? Try searching our database.

Image flickers on use of JScrollPane

Thread view: 
losttemp - 03 Nov 2004 15:46 GMT
Hello!

I am having this weird problem. I am using JScrollPane which displays
a JPanel in a JApplet. The scrollbars appear and also display the
image by using scrollRectToVisible(). But as soon as the scrollbars
appear, the image starts flickering and the image is processed
continuously, also due to which my CPU utilization jumps to 100%.
Also, the image display is set to the rightmost corner of the
ScrollPane and does not slide back or up.

Can someone please help me and guide me in the right direction? I
really want to get over with the flickering and scrolling up/down
problem.

Thanks,
losttemp
Andrew Thompson - 03 Nov 2004 16:29 GMT
> I am having this weird problem.

The code you did not supply does not display the problem you describe.

(snip)
> Can someone please help me and guide me in the right direction?

I suggest you provide an example code that displays the problem.  
For tips on preparing that example, see..
<http://www.physci.org/codes/sscce.jsp>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

losttemp - 04 Nov 2004 16:25 GMT
> > I am having this weird problem.
>
[quoted text clipped - 6 lines]
> For tips on preparing that example, see..
> <http://www.physci.org/codes/sscce.jsp>

I am sorry about not providing sample code. Given below is what I am
doing.

In JApplet,
public void init() {
//some stuff...
scroller = new JScrollPane();
scroller.setOpaque(true);
scroller.getViewport().add(new MyJPanel());
scroller.setPreferredSize(new Dimension(800, 600));
getContentPane().add(scroller, BorderLayout.CENTER);
setVisible(true);
validate();
}

In MyJPanel,
public void paint(Graphics g) {
Dimension area = new Dimension(0,0);
Rectangle rect = new Rectangle(x,y,IMGW,IMGH);
g2d.drawImage(img,x,y,IMGW,IMGH,this);
scrollRectToVisible(rect);
int this_width = (x + W + 5);
if (this_width > area.width) {
    area.width = this_width;
    changed=true;
}
int this_height = (y + H + 50);
if (this_height > area.height) {
   area.height = this_height;
   changed=true;
}
if (changed) {
   setPreferredSize(area);
   scrollRectToVisible(new Rectangle(area.width, area.height, IMGW,
IMGH));
   revalidate();
}

public void mouseDragged(MouseEvent e) {
   x = e.getX();
   y = e.getY();
   /// some stuff...
   // Dimension d stores the current dimensions of the BufferedImage
   Rectangle r = new Rectangle(d.width-600, d.height-400,
d.width+100, d.height+100);
  ((JPanel)e.getSource()).scrollRectToVisible(r);
  repaint();
}
public void mouseMoved(MouseEvent e) {
   // some stuff...
    repaint();
}

Once again, my problem is:
1) When I drag the image such that scrollbars appear, the display area
starts flickering. Other than the (stable)scrollbars already visible,
there is another set of scrollbars visible flickering in the middle of
the display.
2) The scrollbars fix the image at the rightmost lower corner and when
I try to move the scrollbars back or up, they move and then instantly
snap back to the original rightmost lower corner. Hence, not allowing
me to see anything other than the rightmost lower corner.

Please help.
Thanks,
losttemp
Andrew Thompson - 05 Nov 2004 03:50 GMT
>>> I am having this weird problem.
>>
[quoted text clipped - 12 lines]
> In JApplet,
> public void init() {

That does not compile.  You do not seem to have read
the link very carefully.

Please go back and read it again, a hint is to discover what
each of the letters of SSCCE mean ..and how many of them your
code sample did not fit.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.