How to display an ActionToolbar in a table cell ?
Answered
So I have code like this that works properly in almost every place I know off
AnAction source = ActionManager.getInstance().getAction("my_group");
source.getTemplatePresentation().putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, Boolean.TRUE);
DefaultActionGroup actionGroup = new DefaultActionGroup(source);
ActionToolbar t = ActionManager.getInstance().createActionToolbar(
"My_PLACE",
actionGroup,
true);
t.getComponent().setOpaque(false);
t.getComponent().setBorder(JBUI.Borders.empty());
JPanel jPanel = new JPanel(new BorderLayout());
jPanel.add(t.getComponent(), BorderLayout.NORTH);
add(jPanel, BorderLayout.SOUTH); // <----
However if I want to display this toolbar in a cell of `JBTable`, it doesn't work. I've tried multiple things, wrapping in a `JPanel`, setting minimum size, etc. The component don't show up.
class HyperlinkTableCellRenderer implements TableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focus, int row, int column) {
AnAction source = ActionManager.getInstance().getAction("my_group");
source.getTemplatePresentation().putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, Boolean.TRUE);
DefaultActionGroup actionGroup = new DefaultActionGroup(source);
ActionToolbar t = ActionManager.getInstance().createActionToolbar(
"MY_PLACE",
actionGroup,
true);
t.getComponent().setOpaque(false);
t.getComponent().setBackground(RenderingUtil.getBackground(table, selected));
t.getComponent().setBorder(JBUI.Borders.empty());
// t.getComponent().setMinimumSize(t.getComponent().getPreferredSize());
// t.getComponent().setVisible(true);
// Dimension preferredSize = t.getPreferredSize();
// t.setMinimumButtonSize(new Dimension(16, 16));
// t.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
JPanel holder = new JPanel(new BorderLayout());
holder.add(t.getComponent());
return holder;
}
}
I am not as well versed in swing code and behavior as I would be, so I am not sure where to start to debug.
I noticed this on 2021.3, but it's likely present on older versions.
Thank you in advance for any advice.
Post is closed for comments.
Just to make a clarification, I understand that a cell renderer does not make the component active, ie responsive with to mouse events. But in this case the toolbar isn't displayed properly, there's just a dark placeholder in the cell.
please don't crosspost