AllExperts > Java 
Search      
Java
Volunteer
Answers to thousands of questions
 Home · More Java Questions · Answer Library  · Encyclopedia ·
More Java Answers
Question Library

Ask a question about Java
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Artemus Harper
Expertise
I have a BS in computer science and am working towards a Masters degree.

Experience
I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection. knowledge of Java bytecode and annotations. Basics in c++ and c#

Education/Credentials
BS in Computer Science at Central Washington University

 
   

You are here:  Experts > Computing/Technology > Focus on Java > Java > JLabel in JTable

Java - JLabel in JTable


Expert: Artemus Harper - 10/30/2009

Question
Hi, Harper
         I m Nirav Raval Frm India. At now i m develop one Windowbased Application in java with Netbeans IDE 6.0 , in which I have to develop a printable customer bill. In which I m using JTAble to use as a printable bill. Here I have to attch one Image As A logo in the first row of JTable.
         So My Question is how can I Attch that logo with help of JLabel in JTable at particular Cell.?

          Thanks In Advance
          Bi.

Answer
Set the default renderer (for the Object class) in your JTable (using setDefaultRenderer) to a subclass of DefaultTableCellRenderer. In this subclass, override the getTableCellRendererComponent method to return your own JLabel that has your icon in it (just check too see if row and column match what you want, if they don't just call the super implementation).

Also note that you can render html in a JLabel, so using table.setValueAt("<html><img src=\""+YourClass.class.getResource("<<your image Path>>")+"\"/></html>", 0, 0);
will load an image from your jar into the cell. However, unless you adjust the cell width your image may be cut off.

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.