Re: left justify icon in JTable cell



farseer <farseer@xxxxxxxxxxxxx> wrote:

> I have a custom cell renerer that adds and icon to in cell based on a
> condition. If the condition is met, the cell would contain both text
> and the icon. My question is, is there a way to have the icon appear
> left justified, while the text remains centered in cell?
>
> My guess is i my might have to create a panel or something, but i was
> hoping it was possible with a label or other lightweight
> components..(is JPanel light weight)?

Yes, it is. You could use a JPanel with two JLabels (one for the icon,
one for the text) and some layout that would put the icon label first
(left or right) and then the text label (with horizontalAlignment CENTER)
into the remaining space (or really centered).

In this simple case, one could also use a single JLabel and subclass
paint component to paint the extra icon.


Christian
.



Relevant Pages