Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31660 > unrolled thread
| Started by | H.L@operamail.com |
|---|---|
| First post | 2015-05-10 02:57 -0700 |
| Last post | 2015-05-10 14:17 -0700 |
| Articles | 7 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
Animations with jTextPane H.L@operamail.com - 2015-05-10 02:57 -0700
Re: Animations with jTextPane Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-05-10 07:49 -0700
Re: Animations with jTextPane H.L@operamail.com - 2015-05-10 08:08 -0700
Re: Animations with jTextPane Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-05-10 08:54 -0700
Re: Animations with jTextPane Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-05-10 10:28 -0700
Re: Animations with jTextPane H.L@operamail.com - 2015-05-10 13:28 -0700
Re: Animations with jTextPane Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-05-10 14:17 -0700
| From | H.L@operamail.com |
|---|---|
| Date | 2015-05-10 02:57 -0700 |
| Subject | Animations with jTextPane |
| Message-ID | <aabd37b8-2013-4bcb-abef-c787b5c92640@googlegroups.com> |
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 = opencv_highgui.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());
}
}
}
}
[toc] | [next] | [standalone]
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Date | 2015-05-10 07:49 -0700 |
| Message-ID | <minr3t$aua$1@dont-email.me> |
| In reply to | #31660 |
On 5/10/2015 02:57, H.L@operamail.com 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 = opencv_highgui.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
[toc] | [prev] | [next] | [standalone]
| From | H.L@operamail.com |
|---|---|
| Date | 2015-05-10 08:08 -0700 |
| Message-ID | <641b695c-da1e-47d7-95a0-554df722e433@googlegroups.com> |
| In reply to | #31664 |
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øndag den 10. maj 2015 kl. 16.49.42 UTC+2 skrev Knute Johnson:
> On 5/10/2015 02:57, H.L@operamail.com 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 = opencv_highgui.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
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Date | 2015-05-10 08:54 -0700 |
| Message-ID | <minut7$p8v$1@dont-email.me> |
| In reply to | #31665 |
I suggested this because I have some code that I just wrote that uses an
HTML document to display some information on a JTextPane. The data
changes periodically and I just use the setText() method in this case to
change what is displayed. I'm not getting any weird effects and I don't
have to call repaint(). I'm not displaying any images but I don't know
what would be different about that. I'll try some experiments later
today and report back here.
knute...
On 5/10/2015 08:08, H.L@operamail.com 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øndag den 10. maj 2015 kl. 16.49.42 UTC+2 skrev Knute Johnson:
>> On 5/10/2015 02:57, H.L@operamail.com 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 = opencv_highgui.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
>
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Date | 2015-05-10 10:28 -0700 |
| Message-ID | <mio4ee$gnm$1@dont-email.me> |
| In reply to | #31665 |
So my idea may not work so good. I tried a little experiment where I
used some photos from my website and create simple HTML pages and then
loaded them one after another into the JTextPane with setPage(). I get
the flashy too. You can try my test code below. The double buffering
had no effect on the flashing.
It may be easier to put the images in their own component where you can
control the drawing better.
I'll leave the HTML up for a couple of days.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.text.*;
public class test3 extends JTextPane implements Runnable {
public test3() throws IOException {
setPage("http://lonejuniper.com/0.html");
setDoubleBuffered(true);
System.out.println(isDoubleBuffered());
}
public void run() {
int i = 0;
try {
while (true) {
Thread.sleep(1000);
int n = i;
EventQueue.invokeLater(() -> {
try {
setPage(String.format(
"http://lonejuniper.com/%d.html",n));
} catch (IOException ioe) {
ioe.printStackTrace();
}
});
if (++i == 24)
i = 0;
}
} catch (InterruptedException ie) {
System.out.println("program stopping");
}
}
public static void main(String... args) {
EventQueue.invokeLater(() -> {
try {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test3 t3 = new test3();
f.add(t3,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
new Thread(t3).start();
} catch (IOException ioe) {
ioe.printStackTrace();
}
});
}
}
On 5/10/2015 08:08, H.L@operamail.com 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øndag den 10. maj 2015 kl. 16.49.42 UTC+2 skrev Knute Johnson:
>> On 5/10/2015 02:57, H.L@operamail.com 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 = opencv_highgui.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
>
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | H.L@operamail.com |
|---|---|
| Date | 2015-05-10 13:28 -0700 |
| Message-ID | <79d8c03d-890f-4c39-91c7-9a16e435447c@googlegroups.com> |
| In reply to | #31667 |
Den søndag 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
> used some photos from my website and create simple HTML pages and then
> loaded them one after another into the JTextPane with setPage(). I get
> the flashy too. You can try my test code below. The double buffering
> had no effect on the flashing.
>
> It may be easier to put the images in their own component where you can
> control the drawing better.
>
> I'll leave the HTML up for a couple of days.
>
> import java.awt.*;
> import java.awt.event.*;
> import java.io.*;
> import javax.swing.*;
> import javax.swing.text.*;
>
> public class test3 extends JTextPane implements Runnable {
> public test3() throws IOException {
> setPage("http://lonejuniper.com/0.html");
> setDoubleBuffered(true);
> System.out.println(isDoubleBuffered());
> }
>
> public void run() {
> int i = 0;
> try {
> while (true) {
> Thread.sleep(1000);
> int n = i;
> EventQueue.invokeLater(() -> {
> try {
> setPage(String.format(
> "http://lonejuniper.com/%d.html",n));
> } catch (IOException ioe) {
> ioe.printStackTrace();
> }
> });
> if (++i == 24)
> i = 0;
> }
> } catch (InterruptedException ie) {
> System.out.println("program stopping");
> }
> }
>
> public static void main(String... args) {
> EventQueue.invokeLater(() -> {
> try {
> JFrame f = new JFrame();
> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> test3 t3 = new test3();
> f.add(t3,BorderLayout.CENTER);
> f.pack();
> f.setVisible(true);
> new Thread(t3).start();
> } catch (IOException ioe) {
> ioe.printStackTrace();
> }
> });
> }
> }
>
>
> On 5/10/2015 08:08, H.L@operamail.com 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øndag den 10. maj 2015 kl. 16.49.42 UTC+2 skrev Knute Johnson:
> >> On 5/10/2015 02:57, H.L@operamail.com 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 = opencv_highgui.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
> >
>
>
> --
>
> 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?
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Date | 2015-05-10 14:17 -0700 |
| Message-ID | <miohs6$7sr$1@dont-email.me> |
| In reply to | #31668 |
On 5/10/2015 13:28, H.L@operamail.com wrote:
> Den søndag 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 used some photos from my website and create simple HTML pages and
>> then loaded them one after another into the JTextPane with
>> setPage(). I get the flashy too. You can try my test code below.
>> The double buffering had no effect on the flashing.
>>
>> It may be easier to put the images in their own component where you
>> can control the drawing better.
>>
>> I'll leave the HTML up for a couple of days.
>>
>> import java.awt.*; import java.awt.event.*; import java.io.*;
>> import javax.swing.*; import javax.swing.text.*;
>>
>> public class test3 extends JTextPane implements Runnable { public
>> test3() throws IOException {
>> setPage("http://lonejuniper.com/0.html"); setDoubleBuffered(true);
>> System.out.println(isDoubleBuffered()); }
>>
>> public void run() { int i = 0; try { while (true) {
>> Thread.sleep(1000); int n = i; EventQueue.invokeLater(() -> { try
>> { setPage(String.format( "http://lonejuniper.com/%d.html",n)); }
>> catch (IOException ioe) { ioe.printStackTrace(); } }); if (++i ==
>> 24) i = 0; } } catch (InterruptedException ie) {
>> System.out.println("program stopping"); } }
>>
>> public static void main(String... args) { EventQueue.invokeLater(()
>> -> { try { JFrame f = new JFrame();
>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); test3 t3 = new
>> test3(); f.add(t3,BorderLayout.CENTER); f.pack();
>> f.setVisible(true); new Thread(t3).start(); } catch (IOException
>> ioe) { ioe.printStackTrace(); } }); } }
>>
>>
>> On 5/10/2015 08:08, H.L@operamail.com 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øndag den 10. maj 2015 kl. 16.49.42 UTC+2 skrev Knute
>>> Johnson:
>>>> On 5/10/2015 02:57, H.L@operamail.com 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 =
>>>>> opencv_highgui.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
>>>
>>
>>
>> --
>>
>> 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?
If you just need to display an image in a Component, yes. It's not
clear to me what else you have in that JTextPane besides your icon.
The JTextPane appears to be clearing itself and then drawing the image.
In a JComponent, you can just draw the image. No white flash as the
background is drawn with the example below.
I guess I wasn't seeing the flash in my program that I mentioned because
the background is white and their wasn't much being drawn.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
public class test4 extends JPanel implements Runnable {
volatile BufferedImage image;
public test4() {
setPreferredSize(new Dimension(330,180));
}
public void run() {
int i = 0;
while (true) {
try {
if (i > 23)
i = 0;
URL url = new URL(
String.format("http://lonejuniper.com/%d.jpg",i++));
image = ImageIO.read(url);
repaint();
Thread.sleep(1000);
} catch (IOException|InterruptedException ex) {
ex.printStackTrace();
}
}
}
public void paintComponent(Graphics g) {
if (image != null)
g.drawImage(image,0,0,330,180,null);
}
public static void main(String... args) {
EventQueue.invokeLater(() -> {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test4 t4 = new test4();
f.add(t4,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
new Thread(t4).start();
});
}
}
--
Knute Johnson
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web