• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Displaying an image in a TextArea

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to display an image in a TextArea?
If so , using what?

thanks in advance.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not possible. Use JEditorPane/JTextPane.

Add the image in SimpleAttributeSet using StyleConstants.setIcon()

and then call pane.getDocument().insertString(offset, " ", theAttributesWitImage);

Regards,
Stas
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or to insert an Icon at the current caret position you can use:

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you talking about a background image,
where your text appears over the image?
 
rohith yenumula
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


are you talking about a background image,
where your text appears over the image?



No. I am trying to create network simulator in which a user can create his own network. The first step being placing the image icons of a router in an empty space and connecting them with a line.Actually I have one more doubt here. How to allow the user to draw a line between two icons?

Thanks in advance
 
Sheriff
Posts: 28346
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wanted to display images. And now you want to draw lines? It's looking more and more of a bad idea to choose a text component for this. Maybe you should think again? You can draw on a JPanel, so that might be a better choice.
 
rohith yenumula
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can spare some time, have a look at this page.http://www.mathiaz.com/index.php?n=Routage.Routage
Start the applet and choose the distance vector routing algorithm. In the space provided one can draw a network using the left click to display an icon and the right click to draw a line between two icons. I want to make something similar using swing.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rohith yenumula wrote:If you can spare some time, have a look at this page.http://www.mathiaz.com/index.php?n=Routage.Routage
Start the applet and choose the distance vector routing algorithm. In the space provided one can draw a network using the left click to display an icon and the right click to draw a line between two icons. I want to make something similar using swing.



Yes it can absolutely be done. As noted above, many would do the drawing in a JPanel.
 
rohith yenumula
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks pete for taking your time off. One thing that worries a bit is how to enable the user to draw lines between the two icons. If you have any idea please share it.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rohith yenumula wrote:Thanks pete for taking your time off. One thing that worries a bit is how to enable the user to draw lines between the two icons. If you have any idea please share it.



Myself, I'd have a non-GUI model that knows what the icons represent and their location as well as knows about and manages the connection lines. I'd have a drawing JPanel that uses this model to draw the icons in their positions as well as the connection lines. I'd give this JPanel both a MouseListener and a MouseMotionListener both of which use the same MouseAdapter object. The MouseAdapter would create tell the model to create the icons on mouse press and to create the connecting lines on mouse drag (if the start position is near one icon and the end position near another) and then would call repaint which would ask the paintComponent method to use the model data to update the image.
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic