Results 1 to 5 of 5
Thread: changing image of a label
- 08-31-2011, 01:55 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
changing image of a label
hi guys,
in my program i have to change the ImageIcon in a label by clicking on the screen.
it works fine, but takes a long time cause i do it like this:
Class Editor:
Class layer:Java Code:public void mouseClicked(MouseEvent event) { layer.tileSetzen(20, 1); //sets the 20th label in the arraylist labels of the class layer to the image number 1 DrawFrame.setVisible(false); DrawFrame.setVisible(true); // this is what i want to get rid of. }
Java Code:public void tileSetzen(int tilenumber, int id) { tiles.get(tilenumber).setImageNummer(id); //ImageNummer is the image that the label shows (20 is another image than 5 for example) redrawImage(tilenumber); }sum up:Java Code:public void redrawImage(int nr) { MainFrame.getContentPane().remove(labels.get(nr)); //remove the label from the container labels.remove(nr); // remove the label from the arraylist imageIcons.remove(nr); // remove the image from the arraylist with the imageIcons imageIcons.add(nr, tileset[tiles.get(nr).gibImageNummer()]); //add the new image at the place where the other one was deleted labels.add(nr, new JLabel(imageIcons.get(nr))); //add a new label at the place where the label was deleted labels.get(nr).setBounds(32*(nr % x), 16*(nr-( nr % x))/y, 32, 32); // sets the new label at the right position MainFrame.getContentPane().add(labels.get(nr)); // adds the new label to the container }
- i remove the label from the container labels
- i remove the label from the arraylist imageIcons
- i remove the imageIcon from the arraylist
- i add a new imageIcon to the arraylist imageIcons (at the same place as the other one was)
- i add a new label to the arraylist labels (at the same place as the other one was)
- i setBounds of the new label
- i add the label to the container
- i set the MainFrame to unvisible
- i set the MainFrame to visibleLast edited by Coold0wn; 08-31-2011 at 02:08 AM.
- 08-31-2011, 02:34 AM #2
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
okay... got a way better solution now...
is it normal that i cant change many icons fast after each other?
i always have to wait .. like a second befor i can change the next
Java Code:public void mouseClicked(MouseEvent event) { int x = event.getX()-8,y = event.getY(); int tilenr = (x-(x % 32))/32 + 40*((y-(y % 32))/32) - 40; layer.get(pickedLayerNummer).tileSetzen(tilenr , pickedTile); }this takes about 1 sekond?Java Code:public void tileSetzen(int TileNummer, int id) { tiles.get(TileNummer).setImageNummer(id); labels.get(TileNummer).setIcon(tileset[tiles.get(TileNummer).gibImageNummer()]); }Last edited by Coold0wn; 08-31-2011 at 02:38 AM.
- 08-31-2011, 05:55 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 08-31-2011, 12:37 PM #4
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
hey, thanks for your help.
i just found out what the problem was. :)
- 09-06-2011, 06:46 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: changing image of a label
So could you please mark the thread solved then!
Similar Threads
-
Display image via label
By mike_ledis in forum Java AppletsReplies: 1Last Post: 06-02-2011, 06:28 PM -
Changing Image color
By Frecow in forum Java 2DReplies: 0Last Post: 04-04-2011, 10:16 AM -
POI changing text to a form label
By natt in forum Advanced JavaReplies: 2Last Post: 09-19-2008, 10:49 AM -
Creating a label with an image
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 04:40 PM -
Label image Question
By Soda in forum New To JavaReplies: 3Last Post: 12-10-2007, 03:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks