9 Replies - 4958 Views - Last Post: 25 July 2011 - 09:16 PM Rate Topic: -----

#1 narayansingh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-July 11

Iconic View in JTable

Posted 21 July 2011 - 09:35 AM

Hi,

How to display JTable contents as icons.

As the contents of explorer are been displayed as icons, list, details or tiles.

Thanks in Advance,
Narayan
Is This A Good Question/Topic? 0
  • +

Replies To: Iconic View in JTable

#2 TFoSSDQ  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 123
  • View blog
  • Posts: 253
  • Joined: 09-December 10

Re: Iconic View in JTable

Posted 21 July 2011 - 09:42 AM

Then load it with icons instead of text? Umm...what's the problem exactly?
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,910
  • Joined: 06-March 08

Re: Iconic View in JTable

Posted 21 July 2011 - 09:54 AM

You need a CellRenderer that will return a JLabel with your Icon into it

http://www.dreaminco...snippet5600.htm


View PostTFoSSDQ, on 21 July 2011 - 12:42 PM, said:

Then load it with icons instead of text? Umm...what's the problem exactly?

You'll have a problem if you try your suggestion. It won't work:
1) it will return the result of the toString() method applied to the Icon
2) even if your trick worked, you will be limited to display only Icon in your cell

This post has been edited by pbl: 21 July 2011 - 09:56 AM

Was This Post Helpful? 1
  • +
  • -

#4 TFoSSDQ  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 123
  • View blog
  • Posts: 253
  • Joined: 09-December 10

Re: Iconic View in JTable

Posted 21 July 2011 - 10:05 AM

View Postpbl, on 21 July 2011 - 11:54 AM, said:

You'll have a problem if you try your suggestion. It won't work:
1) it will return the result of the toString() method applied to the Icon
2) even if your trick worked, you will be limited to display only Icon in your cell

Ah, I swear I've just inserted it before, but I probably did work with a CellRenderer. It's been a while since I've worked with a JTable. Thank you for the reminder.
Was This Post Helpful? 1
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10807
  • View blog
  • Posts: 40,288
  • Joined: 27-December 08

Re: Iconic View in JTable

Posted 22 July 2011 - 04:39 PM

What you will need is in fact a custom TableCellRenderer. It is done in the same way as Displaying a JComponent in a JTable. Just make sure to set the JComponent's Icon.
Was This Post Helpful? 2
  • +
  • -

#6 narayansingh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-July 11

Re: Iconic View in JTable

Posted 23 July 2011 - 06:47 AM

Hi All,

I'm sorry for my english.

I what to display some data with icons, as shown in the attachement.

Attached Image

Is this can be done. Please help.

Thank you All.
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10807
  • View blog
  • Posts: 40,288
  • Joined: 27-December 08

Re: Iconic View in JTable

Posted 23 July 2011 - 10:12 AM

Yes, it can be done. We just told you how in our previous posts.
Was This Post Helpful? 2
  • +
  • -

#8 narayansingh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-July 11

Re: Iconic View in JTable

Posted 25 July 2011 - 04:20 AM

Hi,

Thank you all, for your help :)

I'm able to display my data with icon and text below it, by using custom renderers.

I got another problem, but all the records are getting displayed at the bottom of other, which is the normal behaviour of table.

I mean by adding an another row, it will be displayed at the bottom of the existing records.

But, how make all the a newly added row beside one another, like shown in the previous screenshot...

Thank you All,
Narayan.

View Postmacosxnerd101, on 23 July 2011 - 10:12 AM, said:

Yes, it can be done. We just told you how in our previous posts.

Was This Post Helpful? 0
  • +
  • -

#9 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Iconic View in JTable

Posted 25 July 2011 - 04:49 AM

Just use setValueAt() to set whatever cell you want to set. Or you can go a more complicated route a change the default way data is added to your table(but this is a lot more complicated than the first option)
Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,910
  • Joined: 06-March 08

Re: Iconic View in JTable

Posted 25 July 2011 - 09:16 PM

View Postnarayansingh, on 23 July 2011 - 09:47 AM, said:

Hi All,

I'm sorry for my english.

I what to display some data with icons, as shown in the attachement.

Attachment ScreenShot002.png

Is this can be done. Please help.

Thank you All.

For that type of display I would rather use a GridLayout than a JTable even if "you can do whatever you want with JTable"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1