0

I have a JScrollPane with a View. I'm doing a chat application , it's why i need to have my ScrollBar to the Maximum(). To get the right Maximum of the View i have to validate before. When I validate my ScrollPane an automatic repaint is doing. I don't want this repaint because it makes a double repaint when i set the ScrollBar to the Maximum : when the ScrollBar is at the top and a another when it is a the bottom.

my code :

Main.getWindow().getMainPanel().getScrollPaneCenter().validate();
scrollPaneCenter.getVerticalScrollBar().setValue(scrollPaneCenter.getVerticalScrollBar().getMaximum());

PS : I want to disable the repaint of my conponent or maybe you have a solution to have a reversed JScrollPane( to always have the ScrollBar to Bottom) .

mKorbel
  • 109,525
  • 20
  • 134
  • 319
g3r4n
  • 105
  • 1
  • 9

1 Answers1

1

I'm doing a chat application

I'm guessing your are using a a JTextArea or JTextPane.

it's why i need to have my ScrollBar to the Maximum().

You don't need to validate or set the scrollbar manually. You juat append the text to the bottom of the Document. See Text Area Scrolling for a couple of solutions.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • I'm using a JPanel inside my JScrollPane. I'll try JTextPane do you think it's the bes way to just display Some Component ? ( I have made Bubble for the conversation in the chat ) – g3r4n Jul 25 '13 at 16:32
  • i would like to do something like that but it's not working . ( because of the layout ? ) `JTextPane pan = new JTextPane();
    pan.setBackground(new Color(1, 0, 0, 0));
    pan.setLayout(null);
    int taillePanel = 0;
    for (int i = 0; i < 20; i++) {
    JButton test = new JButton("Button number : " + i);
    test.setBorderPainted(false);
    test.setBounds(0, (i * 75), 250, 75);
    taillePanel += 75;
    pan.insertComponent(test);}
    pan.setPreferredSize(new Dimension(250, taillePanel)); JScrollPane scrollPaneCenter = new JScrollPane(pan);`
    – g3r4n Jul 25 '13 at 17:36