IDEA-300991 Fix image cut off in Tip Dialog when there is no scroll

GitOrigin-RevId: e0c7699a9251a0983b6c3480cb16747457e346ae
This commit is contained in:
Konstantin Hudyakov
2022-10-21 16:31:15 +03:00
committed by intellij-monorepo-bot
parent 5eea93f9b0
commit c0d134a9fa
2 changed files with 15 additions and 6 deletions

View File

@@ -63,6 +63,10 @@ public final class TipDialog extends DialogWrapper {
Dimension minSize = getRootPane().getMinimumSize();
int height = Math.max(prefSize.height, minSize.height);
setSize(prefSize.width, height);
// Hack to free space occupied by JBScrollBar
// For some reason insets are recalculated inside JBViewport.ViewBorder#getBorderInsets()
// but do not update during validation after dialog size change
SwingUtilities.invokeLater(() -> myTipPanel.getContentPanel().getInsets());
}
@NotNull

View File

@@ -51,6 +51,7 @@ public final class TipPanel extends JPanel implements DoNotAskOption {
private static final Logger LOG = Logger.getInstance(TipPanel.class);
private @NotNull final Project myProject;
private @NotNull final JPanel myContentPanel;
private @NotNull final JLabel mySubSystemLabel;
private final StyledTextPane myTextPane;
final AbstractAction myPreviousTipAction;
@@ -68,9 +69,9 @@ public final class TipPanel extends JPanel implements DoNotAskOption {
setLayout(new BorderLayout());
myProject = project;
JPanel contentPanel = new JPanel();
contentPanel.setBackground(TipUiSettings.getPanelBackground());
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
myContentPanel = new JPanel();
myContentPanel.setBackground(TipUiSettings.getPanelBackground());
myContentPanel.setLayout(new BoxLayout(myContentPanel, BoxLayout.Y_AXIS));
mySubSystemLabel = new JLabel() {
@Override
@@ -82,14 +83,14 @@ public final class TipPanel extends JPanel implements DoNotAskOption {
mySubSystemLabel.setForeground(UIUtil.getLabelInfoForeground());
mySubSystemLabel.setBorder(JBUI.Borders.emptyBottom((int)TextParagraph.SMALL_INDENT));
mySubSystemLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
contentPanel.add(mySubSystemLabel);
myContentPanel.add(mySubSystemLabel);
myTextPane = new StyledTextPane();
myTextPane.setBackground(TipUiSettings.getPanelBackground());
myTextPane.setMargin(JBInsets.emptyInsets());
myTextPane.setAlignmentX(Component.LEFT_ALIGNMENT);
Disposer.register(parentDisposable, myTextPane);
contentPanel.add(myTextPane);
myContentPanel.add(myTextPane);
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
@@ -100,7 +101,7 @@ public final class TipPanel extends JPanel implements DoNotAskOption {
// scroll will not be shown in a regular case
// it is required only for technical writers to test whether the content of the new do not exceed the bounds
JBScrollPane scrollPane = new JBScrollPane(contentPanel, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER);
JBScrollPane scrollPane = new JBScrollPane(myContentPanel, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBorder(JBUI.Borders.empty());
centerPanel.add(scrollPane);
@@ -358,6 +359,10 @@ public final class TipPanel extends JPanel implements DoNotAskOption {
return TipsFeedback.getInstance().getLikenessState(tipId);
}
@NotNull JPanel getContentPanel() {
return myContentPanel;
}
@Override
public boolean canBeHidden() {
return true;