Re: Animations with jTextPane

Posted by Knute... on 10. May 2015

On 5/10/2015 02:57, [email protected] wrote:




Hey



We are using OpenCV to grab images from the web cam. The idea is to show the feed in a jTextPane when the user selects to show feed, otherwise other stuff can be shown in the pane. This pane is in a JFrame with lots of other swing objects.



Basic functionality:



IplImage grabbedImage = opencvhighgui.cvQueryFrame(capture);
while ((grabbedImage = opencv
highgui.cvQueryFrame(capture)) !=null)
jTextPane1.insertIcon(new ImageIcon(grabbedImage.getBufferedImage()));



Now, we get problems because this shows multiple video frames. Obviously, it keeps inserting a new image, so they will be placed on top of each other.



We tried to clear the pane and then repaint by doing like this instead:



this.removeIcon();
jTextPane1.repaint();
jTextPane1.insertIcon(new ImageIcon(grabbedImage.getBufferedImage()));



Where removeIcon looks as can be seen below:



But now, it gets flashy, the user can clearly see how the pane is cleared and then repainted, just a flashy slow change of images.



So is there any way to get around both of these issues?



private void removeIcon()
{
for (int i=0; i<jTextpane1.getStyledDocument().getLength(); i++)
{
Element element =
jTextPane1.getStyledDocument().getCharacterElement(i);
AttributeSet attributeSet = element.getAttributes();
Icon icon = StyleConstants.getIcon(attributeSet);
if (icon != null)
{
try
{



       jTextPane1.getStyledDocument().remove(i, 1);
jTextPane1pane.getStyledDocument().insertString(i, " ", new
SimpleAttributeSet());
icon = null;
}
catch (Exception exc)
{
System.out.println("Exception : " + exc.getMessage());
}
}
}


}




Have you tried just putting the image in a StyledDocument and using
setDocument()?





Knute Johnson


05. Apr 2015: Re: Integer.parseInt() and whitespace? by Jukka...

05. Apr 2015: Re: Any good book/website with samples how to run Java in web applications? by dffdf...

05. Apr 2015: Re: Any good book/website with samples how to run Java in web applications? by Arne ...

05. Apr 2015: Re: Integer.parseInt() and whitespace? by Arne ...

05. Apr 2015: Re: Return of the Applets? by Jeff ...

05. Apr 2015: Re: What are the professional development kits for Java by Arne ...

05. Apr 2015: Re: Return of the Applets? by Jerry...

05. Apr 2015: Return of the Applets? by ram a...

05. Apr 2015: Re: Integer.parseInt() and whitespace? by ram a...

04. Apr 2015: Any good book/website with samples how to run Java in web applications? by dffdf...

04. Apr 2015: Re: What are the professional development kits for Java by Arne ...

04. Apr 2015: Integer.parseInt() and whitespace? by galt_...

04. Apr 2015: What are the professional development kits for Java by dffdf...

04. Apr 2015: Re: Client and ... ? by Jeff ...

04. Apr 2015: Muhammad's Sword by BV BV...

04. Apr 2015: Re: how to write this simple program? by Lew l...

04. Apr 2015: Re: Client and ... ? by Lew l...

03. Apr 2015: Re: Simple if-exercises by v_bor...

03. Apr 2015: Re: Simple if-exercises by Marti...

03. Apr 2015: Re: Simple if-exercises by Jeff ...

03. Apr 2015: Re: Simple if-exercises by Marti...

03. Apr 2015: Re: Simple if-exercises by v_bor...

03. Apr 2015: Re: Simple if-exercises by Eric ...

03. Apr 2015: Re: Simple if-exercises by Marti...

03. Apr 2015: Re: Simple if-exercises by Eric ...

03. Apr 2015: Re: Simple if-exercises by v_bor...

03. Apr 2015: Get Access to the Professional Videos of Java at ITeLearn by charl...

02. Apr 2015: Re: Simple if-exercises by Gene ...

02. Apr 2015: Re: Simple if-exercises by Jerry...

02. Apr 2015: Re: Simple if-exercises by Marti...

02. Apr 2015: Re: Simple if-exercises by Jeff ...

02. Apr 2015: Re: Simple if-exercises by Jeff ...

02. Apr 2015: Re: Simple if-exercises by Eric ...

02. Apr 2015: Simple if-exercises by ram a...

01. Apr 2015: Re: .parallelStream() by Sebas...

01. Apr 2015: .parallelStream() by ram a...

01. Apr 2015: Client and ... ? by ram a...

01. Apr 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Haddo...

01. Apr 2015: Re: .parallelStream() by Eric ...

01. Apr 2015: Re: Client and ... ? by Jeff ...

31. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Sebas...

31. Mar 2015: Re: Draw bolder(ly)? by Marti...

31. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Fredr...

31. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Fredr...

31. Mar 2015: Re: Draw bolder(ly)? by Jeff ...

31. Mar 2015: Re: Draw bolder(ly)? by Jeff ...

31. Mar 2015: Re: Draw bolder(ly)? by Knute...

31. Mar 2015: Re: Draw bolder(ly)? by ram a...

30. Mar 2015: For all algorithm enthusiasts by Algo-...

30. Mar 2015: Re: Draw bolder(ly)? by Jeff ...

30. Mar 2015: Re: Draw bolder(ly)? by Jeff ...

30. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Jan B...

30. Mar 2015: Re: Draw bolder(ly)? by Jeff ...

30. Mar 2015: Re: Draw bolder(ly)? by Knute...

30. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Jan B...

30. Mar 2015: Draw bolder(ly)? by Knute...

30. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Eric ...

30. Mar 2015: BASTARDO PUZZONECRIMINALE DAVIDE SERRA (ALGEBRIS TWITTER) HA BECCATO L'INSIDER SU BANCHE POPOLARI DAL MEGALAVASOLDI MAFIOSI PIERLUIGI BOSCHI DI BANCA ETRURIA. SON TUTTI FASCIONDRANGHETISTI, TIPO NOTO VERME PAOLO BARRAI DI WMO, CHE SI FINGON DEL PD.. by CHE S...

30. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Jeff ...

30. Mar 2015: Re: how to write this simple program? by Eric ...

30. Mar 2015: Is it legal to backport code from JDK8 to JDK6? by Haddo...

29. Mar 2015: Re: how to write this simple program? by Jeff ...

29. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

29. Mar 2015: Re: how to write this simple program? by Jeff ...

29. Mar 2015: Re: how to write this simple program? by Jeff ...

29. Mar 2015: Re: how to write this simple program? by John ...

29. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

29. Mar 2015: Re: how to write this simple program? by Eric ...

29. Mar 2015: how to write this simple program? by John ...

29. Mar 2015: Re: Microsoft Spartan will support Applets by Jeff ...

29. Mar 2015: Re: Microsoft Spartan will support Applets by Jeff ...

29. Mar 2015: Re: Microsoft Spartan will support Applets by Jeff ...

29. Mar 2015: Re: Microsoft Spartan will support Applets by Jeff ...

28. Mar 2015: Re: Microsoft Spartan will support Applets by Andre...

28. Mar 2015: Re: Microsoft Spartan will support Applets by Andre...

28. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

28. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

27. Mar 2015: Re: high quality replica dooney bourke handbags, china dooney & bourke by lugga...

27. Mar 2015: Re: using two different versions of JAR files by Jeff ...

27. Mar 2015: Re: Microsoft Spartan will support Applets by Andre...

27. Mar 2015: Re: using two different versions of JAR files by John ...

27. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

27. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

27. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

27. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

27. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

27. Mar 2015: Re: PRINTING DIAMOND SHAPE WITH LOOPS! by rotic...

26. Mar 2015: Re: Microsoft Spartan will support Applets by Silvi...

26. Mar 2015: Re: Microsoft Spartan will support Applets by Qu0ll...

26. Mar 2015: Re: using two different versions of JAR files by Jeff ...

26. Mar 2015: Re: using two different versions of JAR files by Jeff ...

26. Mar 2015: Re: using two different versions of JAR files by Jeff ...

26. Mar 2015: Re: Microsoft Spartan will support Applets by Eric ...

26. Mar 2015: Re: Microsoft Spartan will support Applets by Eric ...

26. Mar 2015: Re: Microsoft Spartan will support Applets by Eric ...

26. Mar 2015: Re: Microsoft Spartan will support Applets by Silvi...

26. Mar 2015: Re: More JWS problems by Roedy...

26. Mar 2015: Re: Microsoft Spartan will support Applets by Silvi...

26. Mar 2015: Re: Microsoft Spartan will support Applets by Eric ...

26. Mar 2015: Re: using two different versions of JAR files by John ...