i tried putting together something from what i found on the net, but i have an error in drawImage. What should i put for the parameters Image? i cant cast my imageicon to an Image nor Graphics. please point out if there are any other parts which i did not do/did wrongly. thanks.
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
Using an ImageIcon here isn't helping you that much: it seems to be used as an easy way to read from a jpeg file, but ImageIO.read is just as easy to use, and returns a BufferedImage, to boot.
That being said, have you studied ImageIcon's API to see if there are any useful methods that would enable you to successfully call drawImage? [ May 02, 2006: Message edited by: Jeff Albertson ]
There is no emoticon for what I am feeling!
tan kian
Ranch Hand
Joined: Apr 24, 2006
Posts: 30
posted
0
ok i solved it already, thks for the reply anyway =) i have another question now though. i have some JComboBoxes, and i need to make it so that when the value in the combobox is changed, the image in the cells will need to be rotated as well according to the value in the combobox. i tried doing this but well nothing happened.
public void init() { final Mycellrender mcr = new Mycellrender(); JComboBox l = new JComboBox(); l.addItem("a"); l.addItem("b"); l.addItem("c"); l.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.toString() == "a") { mcr.setL(1); } else if (e.toString() == "b") { mcr.setL(2); } else if (e.toString() == "c") { mcr.setL(3); } } }
class Mycellrender extends DefaultTableCellRenderer { Random rand = new Random(255); int choosel;
//if a cell is selected if (blah blah blah) { setBackground(Color.GRAY); } else { if (rand.nextInt(100) < 25 || choosel == 1) { //do stuff like rotating an image } else //do other stuff }
return this; }
public void setL(int index) { choosel = index; } }
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
First, a couple suggestions:
1. When asking a new and potentially unrelated question, it's a good idea to start a new thread. 2. Use code tags for your code.
Back to your code: here's a hint. When trying to understand what's wrong with code, break it into smaller pieces. Your code have two parts: one half is listening to a combo box, and the other half is doing something in a table renderer. This two halfs are quite independent. Test each in isolation. For example, your item listener is doing a case analysis on e.toString() -- why not print this string out to see if it is what you are expecting it to be:
System.out.println(e.toString());
Craig Wood
Ranch Hand
Joined: Jan 14, 2004
Posts: 1535
posted
0
There are a number of ways of doing this. The idea in this one is to make up an ImageIcon for each angle in the JComboBox.
tan kian
Ranch Hand
Joined: Apr 24, 2006
Posts: 30
posted
0
thks, i will try it out and come back with any questions.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.