In my IDEA plugin, I hava implement the Configurable to create a settings dialog.
In the method createComponent, I hava create a component A contains a JBCheckBox, it use an actionListener, when it is choosed, the component will remove two LabeledComponent in A.
@Override
public @Nullable JComponent createComponent() {
component = new MySettingsComponent();
panel = component.getConfigPanel();
// 添加监听动作并重绘页面
component.getMyCheckBox().addActionListener(actionEvent -> {
if (component.isChecked()) {
Container container = component.getFieldA().getParent();
if (container != null) {
container.remove(component.getFieldB()); // remove filedB and successed
}
} else {
// try to re-add fieldB or re-create panel
}
Container parent = panel.getParent();
parent.revalidate();
parent.repaint();
});
return panel;
filedA、fieldB are LabeledComponent.
When I was going to add the removed LabeledComponent to A, the layout and position can not be controlled.
Is there any way to solve this? Or is there a way to re-create the component? Or how can I re-open the settings page?
-
open a new dialog
a new dialog comes with fieldB, but the old one still exists and didn’t change
ShowSettingsUtil.getInstance().showSettingsDialog(project, MyConfigurable.class);
-
get the container and add the removed component
but the removedField stays on the top of the panel
Container container = component.myField().getParent();
container.add(removedField, 7); // 7 is the old index of fieldB
I alse tried to remove all components in this panel and re add all components, but they all lined in a row.
or create new panel and reassign to old panel, but the lable title keeps while no lableTextField.