Autoscroll
* Implemented functionality to automatically scroll down when user is on the bottom of the chat and then there are new messages added. * When chat is opened, the vertical scroll bar starts at the bottom. * When rereading messages, the chat doesn't scroll down if new messages are added. (Besides see first point)
This commit is contained in:
parent
b1f9172b63
commit
cda5c37a4a
@ -63,6 +63,8 @@ public class ChatWindow extends JFrame {
|
|||||||
// private JCheckBox jCbChangeMode;
|
// private JCheckBox jCbChangeMode;
|
||||||
private PrimaryButton postButton = new PrimaryButton("Post");
|
private PrimaryButton postButton = new PrimaryButton("Post");
|
||||||
private PrimaryButton settingsButton = new PrimaryButton("Settings");
|
private PrimaryButton settingsButton = new PrimaryButton("Settings");
|
||||||
|
private int verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum();
|
||||||
|
private boolean chatOpened = false;
|
||||||
|
|
||||||
private static int space = 4;
|
private static int space = 4;
|
||||||
|
|
||||||
@ -208,6 +210,7 @@ public class ChatWindow extends JFrame {
|
|||||||
textPane.setText(currentChat.getRecipient().getName());
|
textPane.setText(currentChat.getRecipient().getName());
|
||||||
|
|
||||||
messageList.setModel(currentChat.getModel());
|
messageList.setModel(currentChat.getModel());
|
||||||
|
chatOpened = true;
|
||||||
contentPane.revalidate();
|
contentPane.revalidate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -253,11 +256,8 @@ public class ChatWindow extends JFrame {
|
|||||||
// scrollPane
|
// scrollPane
|
||||||
scrollPane.setForeground(theme.getBackgroundColor());
|
scrollPane.setForeground(theme.getBackgroundColor());
|
||||||
scrollPane.setBackground(theme.getCellColor());
|
scrollPane.setBackground(theme.getCellColor());
|
||||||
// scrollPane.getVerticalScrollBar()
|
|
||||||
// .setBackground(
|
// Scroll Bar Styling
|
||||||
// new Color(theme.getBackgroundColor().getRed() + 50,
|
|
||||||
// theme.getBackgroundColor().getGreen() + 50,
|
|
||||||
// theme.getBackgroundColor().getBlue() + 50));
|
|
||||||
scrollPane.getVerticalScrollBar().setBackground(theme.getCellColor());
|
scrollPane.getVerticalScrollBar().setBackground(theme.getCellColor());
|
||||||
scrollPane.getVerticalScrollBar()
|
scrollPane.getVerticalScrollBar()
|
||||||
.setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(),
|
.setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(),
|
||||||
@ -267,10 +267,26 @@ public class ChatWindow extends JFrame {
|
|||||||
scrollPane.getHorizontalScrollBar()
|
scrollPane.getHorizontalScrollBar()
|
||||||
.setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50),
|
.setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50),
|
||||||
new Color(theme.getInteractableBackgroundColor().getRGB() + 170), false));
|
new Color(theme.getInteractableBackgroundColor().getRGB() + 170), false));
|
||||||
// int currentVerticalScrollBarValue =
|
|
||||||
// scrollPane.getVerticalScrollBar().getValue() +
|
// Autoscroll
|
||||||
// scrollPane.getVerticalScrollBar().getVisibleAmount(); Work in Progress for
|
scrollPane.getVerticalScrollBar().addAdjustmentListener(e -> {
|
||||||
// autoscroll
|
if ((verticalScrollBarMaximumValue - e.getAdjustable().getMaximum()) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chatOpened == true) {
|
||||||
|
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
|
||||||
|
verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum();
|
||||||
|
chatOpened = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (scrollPane.getVerticalScrollBar().getValue()
|
||||||
|
+ scrollPane.getVerticalScrollBar().getVisibleAmount() + 100 >= scrollPane.getVerticalScrollBar().getMaximum()) {
|
||||||
|
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
|
||||||
|
verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// messageEnterTextArea
|
// messageEnterTextArea
|
||||||
messageEnterTextArea.setCaretColor(theme.getTypingMessageColor());
|
messageEnterTextArea.setCaretColor(theme.getTypingMessageColor());
|
||||||
messageEnterTextArea.setForeground(theme.getTypingMessageColor());
|
messageEnterTextArea.setForeground(theme.getTypingMessageColor());
|
||||||
|
Reference in New Issue
Block a user