* fix dnd rendering issue

This commit is contained in:
Reinhard Pointner 2009-03-14 01:01:01 +00:00
parent 9ed970de05
commit 902930ff52
1 changed files with 21 additions and 11 deletions

View File

@ -65,7 +65,7 @@ public class MainFrame extends JFrame {
headerPanel.getTitleLabel().setBorder(new EmptyBorder(8, 90, 10, 0)); headerPanel.getTitleLabel().setBorder(new EmptyBorder(8, 90, 10, 0));
JComponent c = (JComponent) getContentPane(); JComponent c = (JComponent) getContentPane();
c.setLayout(new MigLayout("insets 0, fill", "95px[fill]", "fill")); c.setLayout(new MigLayout("insets 0, fill, hidemode 3", "95px[fill]", "fill"));
c.add(selectionListScrollPane, "pos visual.x+6 visual.y+10 n visual.y2-12"); c.add(selectionListScrollPane, "pos visual.x+6 visual.y+10 n visual.y2-12");
c.add(headerPanel, "growx, dock north"); c.add(headerPanel, "growx, dock north");
@ -105,36 +105,46 @@ public class MainFrame extends JFrame {
protected void showPanel(final PanelBuilder selectedBuilder) { protected void showPanel(final PanelBuilder selectedBuilder) {
headerPanel.setTitle(selectedBuilder.getName()); final JComponent contentPane = (JComponent) getContentPane();
JComponent panel = null; JComponent panel = null;
for (int i = 0; i < getContentPane().getComponentCount(); i++) { for (int i = 0; i < contentPane.getComponentCount(); i++) {
JComponent c = (JComponent) getContentPane().getComponent(i); JComponent c = (JComponent) contentPane.getComponent(i);
PanelBuilder builder = (PanelBuilder) c.getClientProperty("panelBuilder"); PanelBuilder builder = (PanelBuilder) c.getClientProperty("panelBuilder");
if (builder != null) { if (builder != null) {
c.setVisible(false);
if (builder.equals(selectedBuilder)) { if (builder.equals(selectedBuilder)) {
panel = c; panel = c;
} else {
c.setVisible(false);
} }
} }
} }
JComponent contentPane = (JComponent) getContentPane();
if (panel == null) { if (panel == null) {
panel = selectedBuilder.create(); panel = selectedBuilder.create();
panel.putClientProperty("panelBuilder", selectedBuilder); panel.putClientProperty("panelBuilder", selectedBuilder);
contentPane.add(panel, "hidemode 3"); contentPane.add(panel);
} else if (panel.isVisible()) {
// no need to do anything
return;
} }
headerPanel.setTitle(selectedBuilder.getName());
panel.setVisible(true); panel.setVisible(true);
// update layout now
contentPane.validate(); contentPane.validate();
// this seems to fix a very annoying layout/render issue, I've got no clue why
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
contentPane.validate();
}
});
} }
@ -179,7 +189,7 @@ public class MainFrame extends JFrame {
selectEnabled = true; selectEnabled = true;
// bring window to front when on dnd // bring window to front when on dnd
SwingUtilities.getWindowAncestor((JComponent) dtde.getSource()).toFront(); SwingUtilities.getWindowAncestor(((DropTarget) dtde.getSource()).getComponent()).toFront();
} }
}); });
} }