Skip to main content

A ComponentProvider with a JPanel not displayed

11 replies [Last post]
julien1486
Offline
Joined: 2010-01-27
Points: 0

Hi !
I'm using a JXTable (swingx 1.0) and I want to make a custom component provider.
This component provider is a JPanel with a Border Layout, it has a JLabel (CENTER) and a JButton (EAST). Here is my code :
ComponentProvider :

public class MyProvider extends ComponentProvider<MyRenderer> {

/**
*
*/
private static final long serialVersionUID = 1L;

public MyProvider() {
super(new DefaultIdentifiableFormat());

}

@Override
protected void configureState(final CellContext paramCellContext) {
rendererComponent.getLbl().setHorizontalTextPosition(SwingConstants.LEFT);
}

@Override
protected MyRenderer createRendererComponent() {
return new MyRenderer();
}

@Override
protected void format(final CellContext paramCellContext) {
rendererComponent.setText(getValueAsString(paramCellContext));
}
}

And here is the "MyRenderer" class :
public class MyRenderer extends JPanel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel panel;
private JideButton btDelete;
private JLabel lbl;

public MyRenderer() {
panel = new JPanel(new BorderLayout());
btDelete = new JideButton(ImagesUtil.getIcon("delete.png"));
btDelete.addActionListener(this);
panel.add(btDelete, BorderLayout.EAST);
lbl = new JLabel();
panel.add(lbl, BorderLayout.CENTER);
}

@Override
public void actionPerformed(final ActionEvent e) {
System.out.println("Clicked !");
}

public JideButton getBtDelete() {
return btDelete;
}

public JLabel getLbl() {
return lbl;
}

public JPanel getPanel() {
return panel;
}

public void setBtDelete(final JideButton btDelete) {
this.btDelete = btDelete;
}

public void setIcon(final Icon ico) {
btDelete.setIcon(ico);
}

public void setLbl(final JLabel lbl) {
this.lbl = lbl;
}

public void setPanel(final JPanel panel) {
this.panel = panel;
}

public void setText(final String txt) {
lbl.setText(txt);
}
}

So I've tried this but nothing is displayed, I can select "something" but nothing appears (when selected there is just the blue background).
Is it possible to make this renderer ? Will my button be "clickable" ?

Thanks a lot for your help

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
julien1486
Offline
Joined: 2010-01-27
Points: 0

Actually I don't know if what I want to do is possible.
I want to display a List with some items in it. In this list I want to display a "Delete" button which has just an icon.
What I want is to display the button only for the row which is "rolled over" in order to get a clear design. When the user click on the button the row is deleted.
Is it possible to do something like that ?

kleopatra
Offline
Joined: 2003-06-11
Points: 0

the unsupported part of that is the "user click on the button" vs. user clicks anywhere in the row.
SwingX rollover-support is per-cell (intentionally so): an implementation of rolloverRenderer can change itself as needed. In your context that would be setting the button visible on rollover and invisible if not (beware: you need a LayoutManager with does layout invisible components just it would visible components!) Or simply show/hide an icon in the rendering label.
Detecting if the mouse is over a particular sub-area of the cell is left to client code ;-) The incubator has some experiments (look for checklist) trying to introduce a concept like "hotspot-aware", we never made it to polish them enough for inclusion, doesn't yet feel quite right.
CU
Jeanette
BTW: is your duplicate post intentional or yet another hick-up of the damned forum software? If the latter, I will delete it - please let me know

julien1486
Offline
Joined: 2010-01-27
Points: 0

Thanks for your answer Jeanette.

The duplicate post was intentional. This answer was not related to my previous post so I choosed to reply to my first post, but I expected the answer to be located at the end of the page with a different left shift. Actually it is located here :D Sorry for that.

klbsjpolp
Offline
Joined: 2005-04-23
Points: 0

Nothing happen because you do nothing with your panel in MyRenderer. Why don't you just add the label and the button to the renderer instead of using another panel?

julien1486
Offline
Joined: 2010-01-27
Points: 0

Well... thanks for your help klbsjpolp.
I think I was a little tired yesterday :D I forgot than MyRenderer extended JPanel. So I've added the JLabel and JButton to the "MyRenderer" itself and they are correctly displayed now.
The problem now is that the button does not respond to any event

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Renderers are not interactive; editors are.
Karl

julien1486
Offline
Joined: 2010-01-27
Points: 0

Ok and JXlist is not editable...
I will try something else :)
Thanks for your answers !

klbsjpolp
Offline
Joined: 2005-04-23
Points: 0

The RolloverRenderer can catch the click but it is missing features. So you know there is a click, but you can't easily known where it happens.

julien1486
Offline
Joined: 2010-01-27
Points: 0

If the click can select the line I think it would be possible to use the selection model

julien1486
Offline
Joined: 2010-01-27
Points: 0

Actually I don't know if what I want to do is possible.
I want to display a List with some items in it. In this list I want to display a "Delete" button which has just an icon.
What I want is to display the button only for the row which is "rolled over" in order to get a clear design. When the user click on the button the row is deleted.

klbsjpolp
Offline
Joined: 2005-04-23
Points: 0

The easiest way would be to use a JXTable with 2 columns and an highlighter to show the Delete in the rollover row of the delete column. Then, use a RolloverRenderer to catch the click on the Delete cell.