Results 1 to 20 of 20
Thread: Coloring an image
- 08-29-2009, 04:20 PM #1
Coloring an image
Hello everyone, my JFrame has two panels, top and bottom, and the top contains two items, my map and the information(JTextArea). I'm currently using the "image in a JLabel" method to display the map, but now I know that isn't going to work for my purposes. I want to color the area on the map to whatever they select, but I can't use 2D graphics because then my information JTextArea will be moved to the center, and the image will cover it up. So how would I go about doing this?
If you need any more information just say so.
Thank you
~TwitchThe one who laughs last is teh stupid.
:3
- 08-29-2009, 04:34 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 08-29-2009, 04:41 PM #3
- 08-29-2009, 04:45 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Still you should be able to display both the 2D graphic and the textarea at the same time, right?
- 08-29-2009, 04:53 PM #5
I can, but like I said, when I draw the image it covers up the textarea because you can't put 2D graphics in a JPanel, or can you?
The one who laughs last is teh stupid.
:3
- 08-29-2009, 05:22 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Where are you currently drawing the image on?
Did you try putting it on the panel?
- 08-29-2009, 05:27 PM #7
I just tried to draw the image, can you put the image on a JPanel, and if you can I'm going to wonder why I was to stupid not to see that :p.
The one who laughs last is teh stupid.
:3
- 08-29-2009, 10:23 PM #8
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Why don't you post the code where you have tried and failed by getting the overlap.
- 08-30-2009, 01:22 AM #9
Taking code out because it's sloved
But if you take out the JLabel, and try to draw the image it will overlap it.Last edited by Twitchy5; 09-04-2009 at 08:25 PM. Reason: taking out code
The one who laughs last is teh stupid.
:3
- 08-30-2009, 05:51 AM #10
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Let's see the code where to tried to draw the image and got the overlapping behavior.
- 08-30-2009, 04:46 PM #11
Well, it seems I've ran into a bit of bad luck, I lost the code with the paint method and I cannot find it on google, so what way would you draw an image on a Jpanel without being a background?
The one who laughs last is teh stupid.
:3
- 08-30-2009, 09:06 PM #12
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You lost your code on google? No wonder some people seem to be avoiding google when you'd think that they need it badly.
- 08-30-2009, 10:05 PM #13
Don't get me wrong now, I code my own stuff, but to learn certain things I look on google like any other thing, and since this is my first time doing something like this, I don't know the code, and I tried looking on the API and seeing what methods do what, but sometimes you need help.
The one who laughs last is teh stupid.
:3
- 08-30-2009, 10:35 PM #14
- 08-31-2009, 04:05 AM #15
The one who laughs last is teh stupid.
:3
- 08-31-2009, 08:00 AM #16
Then maybe you need this:
Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI with JFC/Swing)
db
- 09-04-2009, 08:24 PM #17
Ok guys I got it, what I did was this:
Java Code:BufferedImage image = ImageIO.read(new File(filename)); ImageIcon img = new ImageIcon(image); JLabel map = new JLabel(img); //to paint: private void paintTerritories(int ter) { //do whatever with the BufferedImage frame.update(); }The one who laughs last is teh stupid.
:3
- 09-11-2009, 11:46 AM #18
1. Perform custom painting in a JComponent or JPanel, not is a top-level container like JFrame (or JDialog/JApplet).
2. Call repaint(), not update() to update your GUI.
Looks like you aren't interested in going through helpful links, so you'll probably ignore this too.
db
- 09-12-2009, 03:28 PM #19
No, I went to the links, and they said little about how to paint a picture, and I know my layouts. And repaint() just calls the update() usually.
The one who laughs last is teh stupid.
:3
-
Hello Twitchy. This article goes into more depth on the painting of heavy weight and light weight components, gives general guidelines on painting in Swing, and gives reasons not to directly invoke update with Swing:
Painting in AWT and Swing
Much luck.
Similar Threads
-
Problems drawing a section of an image onto another image.
By Cain in forum Java 2DReplies: 1Last Post: 04-17-2009, 12:44 AM -
[SOLVED] manipulating the pixel values of an image and constructinf a new image from
By sruthi_2009 in forum AWT / SwingReplies: 14Last Post: 04-10-2009, 08:46 AM -
drawing an image to an offscreen image
By hunterbdb in forum Java 2DReplies: 9Last Post: 10-30-2008, 06:17 PM -
Implementing syntax coloring using the StyledText API
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:31 PM -
Converting multiple banded image into single banded image... Image enhancement
By archanajathan in forum Advanced JavaReplies: 0Last Post: 01-08-2008, 05:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks