• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Rotating an imageicon in JTable cells

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
tan kian
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;

public Component getTableCellRendererComponent(JTable jt,Object value,boolean isselected, boolean hasfocus,int row,int col)
{
super.getTableCellRendererComponent(jt,value,isselected,hasfocus,row,col);

//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
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thks, i will try it out and come back with any questions.
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic