Re: Animations with jTextPane

Posted by H L a... on 10. May 2015

Den s=F8ndag den 10. maj 2015 kl. 19.28.59 UTC+2 skrev Knute Johnson:




So my idea may not work so good. I tried a little experiment where I=20
used some photos from my website and create simple HTML pages and then=20
loaded them one after another into the JTextPane with setPage(). I get=
=20
the flashy too. You can try my test code below. The double buffering=20
had no effect on the flashing.
=20
It may be easier to put the images in their own component where you can=
=20
control the drawing better.
=20
I'll leave the HTML up for a couple of days.
=20
import java.awt.;
import java.awt.event.
;
import java.io.;
import javax.swing.
;
import javax.swing.text.*;
=20
public class test3 extends JTextPane implements Runnable {
public test3() throws IOException {
setPage("http://lonejuniper.com/0.html");
setDoubleBuffered(true);
System.out.println(isDoubleBuffered());
}
=20
public void run() {
int i =3D 0;
try {
while (true) {
Thread.sleep(1000);
int n =3D i;
EventQueue.invokeLater(() -> {
try {
setPage(String.format(
"http://lonejuniper.com/%d.html",n));
} catch (IOException ioe) {
ioe.printStackTrace();
}
});
if (++i =3D=3D 24)
i =3D 0;
}
} catch (InterruptedException ie) {
System.out.println("program stopping");
}
}
=20
public static void main(String... args) {
EventQueue.invokeLater(() -> {
try {
JFrame f =3D new JFrame();
f.setDefaultCloseOperation(JFrame.EXITONCLOSE);
test3 t3 =3D new test3();
f.add(t3,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
new Thread(t3).start();
} catch (IOException ioe) {
ioe.printStackTrace();
}
});
}
}
=20
=20
On 5/10/2015 08:08, [email protected] wrote:




Thank you for helping me with this. We have not tried this, but
please note that we are continouusly changing what image is shown.
The web cam captures a new image and this is shown on the screen, how
could we do this updating with setDocument()?



Den s=F8ndag den 10. maj 2015 kl. 16.49.42 UTC+2 skrev Knute Johnson:




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 =3D opencvhighgui.cvQueryFrame(capture);
while ((grabbedImage =3D opencv
highgui.cvQueryFrame(capture))
!=3Dnull) 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=3D0;
i<jTextpane1.getStyledDocument().getLength(); i++) { Element
element =3D jTextPane1.getStyledDocument().getCharacterElement(i);
AttributeSet attributeSet =3D element.getAttributes(); Icon icon =3D
StyleConstants.getIcon(attributeSet); if (icon !=3D null) { try {



jTextPane1.getStyledDocument().remove(i, 1);
jTextPane1pane.getStyledDocument().insertString(i, " ", new
SimpleAttributeSet()); icon =3D 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




=20
=20
--=20
=20
Knute Johnson





Yes, this is quite exactly what we are experiencing. So are you suggesting =
that we should use something else rather than a JTextPane?


03. Jun 2015: Re: Why do we need to "@Override Object clone" if all classes are subclasses of Object, why can not directly involke the functin? by Arne ...

02. Jun 2015: Re: Design pattern used to mask account number in an ATM or POS transaction by Arne ...

02. Jun 2015: Design pattern used to mask account number in an ATM or POS transaction by Ajay ...

01. Jun 2015: Re: Wiring: A topic underrepresented in teaching? by Silvi...

01. Jun 2015: Wiring: A topic underrepresented in teaching? by ram a...

01. Jun 2015: Re: Wiring: A topic underrepresented in teaching? by Eric ...

30. May 2015: I 2 BASTARDI LAVA CASH MAFIOSO DAVIDE SERRA DI ALGEBRIS E PAOLO BARRAI (AVANZO DI GALERA: 3 VOLTE IN CARCERE IN VITA SUA) FAN STALKING ASSASSINO A GENIO BORSISTICO ED EROE CIVILE MICHELE NISTA, SU ORDINE DI NAZIMAFIOSO PEDOFILO SILVIO BERLUSCONI E.. by CHE S...

29. May 2015: Re: Why do we need to "@Override Object clone" if all classes are subclasses of Object, why can not directly involke the functin? by Eric ...

28. May 2015: Re: Why do we need to "@Override Object clone" if all classes are subclasses of Object, why can not directly involke the functin? by HU Ti...

28. May 2015: Re: Why do we need to "@Override Object clone" if all classes are subclasses of Object, why can not directly involke the functin? by HU Ti...

28. May 2015: Re: Why do we need to "@Override Object clone" if all classes are subclasses of Object, why can not directly involke the functin? by Arne ...

28. May 2015: Why do we need to "@Override Object clone" if all classes are subclasses of Object, why can not directly involke the functin? by pigeo...

26. May 2015: Re: Recommendation for a good Android programming book? by Marti...

26. May 2015: Re: Recommendation for a good Android programming book? by Marti...

26. May 2015: Re: Java DatePicker popup calendar by Nigel...

26. May 2015: Re: Recommendation for a good Android programming book? by Eric ...

26. May 2015: Re: Recommendation for a good Android programming book? by Joerg...

26. May 2015: Re: Recommendation for a good Android programming book? by Marti...

26. May 2015: Re: Java DatePicker popup calendar by e d p...

26. May 2015: Re: Recommendation for a good Android programming book? by Knute...

25. May 2015: Re: Recommendation for a good Android programming book? by Knute...

24. May 2015: Re: How to read the Java tutorial offline? by David...

23. May 2015: SQLite database by Ram V...

23. May 2015: Java DatePicker popup calendar by Danie...

23. May 2015: Human Rights and Justice in Islam by bv4bv...

22. May 2015: Re: Can we convert a Java ResultSet/SqlRowSet from Database query directly to JSON array without Mapping it to a List<Type>? by Arne ...

22. May 2015: Re: Recommendation for a good Android programming book? by e d p...

22. May 2015: Can we convert a Java ResultSet/SqlRowSet from Database query directly to JSON array without Mapping it to a List<Type>? by kaush...

21. May 2015: Re: Recommendation for a good Android programming book? by ram a...

21. May 2015: Re: Recommendation for a good Android programming book? by Arne ...

20. May 2015: Java and C# and Threadpool by Ramin...

20. May 2015: Re: JScrollPane not scrolling smoothly on fast computer by Jim H...

20. May 2015: Recommendation for a good Android programming book? by Knute...

20. May 2015: Re: JScrollPane not scrolling smoothly on fast computer by Knute...

18. May 2015: Re: Main Loop porblm by Silvi...

18. May 2015: Re: Main Loop porblm by Eric ...

18. May 2015: Re: Main Loop porblm by Micha...

18. May 2015: Main Loop porblm by Micha...

18. May 2015: Re: Puzzler: Fun with Streams. by scatt...

18. May 2015: Re: Puzzler: Fun with Streams. by scatt...

17. May 2015: Re: get a list of classes at runtime by Arne ...

17. May 2015: Re: get a list of classes at runtime by Arne ...

16. May 2015: C*C*C: CIUCCIA CAZZI DI CAVALLO PAOLO BARRAI DI WMO E BSI ITALIA SRL, UNA VOLTA CACCIATO (E FATTO CONDANNARE A GALERA) DA CITIBANK, PRIMA DI SPENNARE POLLI VIA WEB, FECE FILM PEDOPORNOMOSESSUALI! E CON CAVALLI! CIUCCIANDO E PRENDENDO FALLI EQUINI E.. by CARME...

15. May 2015: Need Oracle DBA Resumes for the position in Chicago,IL by srini...

14. May 2015: About Java... by Ramin...

14. May 2015: Re: JNI Wrapper for Delphi and FreePascal version 2.82 is here.. by Ramin...

14. May 2015: JNI Wrapper for Delphi and FreePascal version 2.82 is here.. by Ramin...

14. May 2015: Re: [Javascript] Uncaught ReferenceError: Invalid left-hand side in assignment by ram a...

14. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Rober...

13. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

13. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

13. May 2015: Re: get a list of classes at runtime by Joshu...

13. May 2015: Re: [Javascript] Uncaught ReferenceError: Invalid left-hand side in assignment by Joshu...

13. May 2015: [Javascript] Uncaught ReferenceError: Invalid left-hand side in assignment by garlo...

13. May 2015: [Javascript] How do I find out what this bug means and how to fix it? Uncaught ReferenceError: Invalid left-hand side in assignment by garlo...

13. May 2015: Re: get a list of classes at runtime by j4n b...

13. May 2015: Re: get a list of classes at runtime by Joerg...

13. May 2015: Re: get a list of classes at runtime by Phili...

13. May 2015: Re: get a list of classes at runtime by Eric ...

13. May 2015: Re: Puzzler: Fun with Streams. by Danie...

13. May 2015: Re: get a list of classes at runtime by Eric ...

13. May 2015: Re: get a list of classes at runtime by Eric ...

13. May 2015: Re: How to programatically limit the number of threads in a java by Joerg...

13. May 2015: Re: get a list of classes at runtime by e d p...

13. May 2015: Re: Puzzler: Fun with Streams. by Jeff ...

13. May 2015: Call for Papers: World Congress on Engineering and Computer Science WCECS 2015 by iaeng...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

12. May 2015: Re: How to programatically limit the number of threads in a java by Marce...

12. May 2015: Re: JScrollPane not scrolling smoothly on fast computer by Knute...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

12. May 2015: Puzzler: Fun with Streams. by Danie...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Rober...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by ram a...

12. May 2015: Re: Use URL for HTTPS request using Proxy by Silvi...

12. May 2015: Use URL for HTTPS request using Proxy by Silvi...

12. May 2015: Re: what are the senarios when we should override equals and hashcode by Lew l...

12. May 2015: JNI Wrapper for Delphi and FreePascal version 2.8 by Ramin...

12. May 2015: Re: How to programatically limit the number of threads in a java by Eric ...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Ajay ...

12. May 2015: How to programatically limit the number of threads in a java by Ajay ...

12. May 2015: Re: API vc MVC by Joerg...

12. May 2015: Need Java Developers/Tech Leads/Architects at Reston, VA (Permanent) by ashok...

11. May 2015: API vc MVC by Leona...

11. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...

11. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Gene ...

11. May 2015: Re: JScrollPane not scrolling smoothly on fast computer by e d p...

11. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by v_bor...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Joerg...

10. May 2015: Re: Animations with jTextPane by H L a...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: Animations with jTextPane by H L a...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

10. May 2015: how does a marker interface give specific instruction to jvm(java internals) by Ajay ...

10. May 2015: Animations with jTextPane by H L a...

09. May 2015: JScrollPane not scrolling smoothly on fast computer by Knute...

09. May 2015: PEZZO DI MERDA BASTARDO DAVIDE SERRA DI ALGEBRIS INVESTMENTS - TWITTER, HA RICEVUTO INSIDER SULLE POPOLARI DAL MEGALAVA SOLDI MAFIOSI PIER LUIGI BOSCHI DI BANCA ETRURIA! SON TUTTI NAZISTI, TIPO NOTO VERME PAOLO BARRAI DI WMO, CHE SI FINGON DEL PD X.. by CARME...

09. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...