Skip to content

Commit

Permalink
fix: Chat area repaint when the tool window resizes
Browse files Browse the repository at this point in the history
  • Loading branch information
uc4w6c committed Jan 27, 2025
1 parent d934bdf commit d875ddc
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.function.Function;

public class BedrockAssistantToolWindow {
Expand All @@ -34,6 +36,21 @@ public JPanel getContent() {
conversationArea.setLayout(new BoxLayout(conversationArea, BoxLayout.Y_AXIS));
conversationArea.setMaximumSize(new Dimension(CONVERSATION_AREA_MAX_WIDTH, Integer.MAX_VALUE));
conversationScrollPane = new JScrollPane(conversationArea);
conversationScrollPane.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent componentEvent) {
for (Component component : conversationArea.getComponents()) {
if (component instanceof JPanel) {
component.setMaximumSize(
new Dimension(
conversationScrollPane.getViewport().getWidth(),
component.getPreferredSize().height));
}
conversationArea.revalidate();
conversationArea.repaint();
}
}
});

inputArea = new JBTextArea();
inputArea.setLineWrap(true);
Expand Down Expand Up @@ -87,9 +104,14 @@ private void addConvesertion(Icon roleIcon, String message) {
messageArea.setWrapStyleWord(true);
messageArea.setEditable(false);

messageArea.setMaximumSize(new Dimension(conversationScrollPane.getViewport().getWidth(), Integer.MAX_VALUE));

messagePanel.add(iconLabel, BorderLayout.WEST);
messagePanel.add(messageArea, BorderLayout.CENTER);

messagePanel.setMaximumSize(new Dimension(conversationScrollPane.getViewport().getWidth(), messagePanel.getPreferredSize().height));
messagePanel.setAlignmentX(Component.LEFT_ALIGNMENT);

conversationArea.add(messagePanel);
conversationArea.revalidate();
conversationArea.repaint();
Expand All @@ -102,5 +124,4 @@ private void addConvesertion(Icon roleIcon, String message) {
verticalScrollBar.setValue(verticalScrollBar.getMaximum());
});
}

}

0 comments on commit d875ddc

Please sign in to comment.