G
Guest
How do I force a JLabel (with HTML content) wrapped in a JScrollPane to
automatically scroll to the last line added ?
I am developing an applet whose frame is divided in three panels:
- the top one is a tabbed pane which normally contains an astronomical
image (may contain also some "control" menus, irrelevant here)
- the middle one is a JLabel wrapped in a JScrollPane
- the bottom one is a JTable also wrapped in a JScrollPane
The applet retrieves from the web the image (which is displayed in the
top panel) and a "region file" (a list of sky positions with associated
a shape, circle, box, ellipse etc. and other info). The region file is
loaded in the bottom JTable, and displayed graphically onto the top
image.
Then I have a mouse adapter which, clicking onto the image, locates the
nearest region (within a tolerance, otherwise shall issue a "no region"
message). Let's assume that the region is at index "nearest" in the
Vector of region records
RegionRecord rr=(RegionRecord) mtm.rrs.elementAt(nearest)
On a successful click, I hilight the row associated to the nearest
record in the JTable mytable. To do this I do
mytable.changeSelection(nearest,0,false,false)
(or mytable.clearSelection() if no region is located). This
automatically scrolls the Jtable up or down to put the hilighted region
row in sight.
At the same time, on each click I write a message to the middle panel,
via a method which ultimately does
msg.setText(msg.getText()+"<br>"+mymessage) ;
where msg is the Jlabel in the middle panel. This is followed by a
repaint of the overarching applet content pane.
The point is that, once the panel is full, a scrollbar appears, but the
(added) bottom line is no longer on the screen (the scroll bar has to be
scrolled manually).
I tried playing with msg.setVerticalAlignment() to TOP or BOTTOM but it
seems to have no effect once the scrollbar appears.
How do I force the JLabel wrapped in the JScrollPane to automatically
scroll to the last line added ?
(BTW the reason I used a JLabel instead of a JTextArea is in order to be
use HTML tags to format differently errors, warnings and info messages).
automatically scroll to the last line added ?
I am developing an applet whose frame is divided in three panels:
- the top one is a tabbed pane which normally contains an astronomical
image (may contain also some "control" menus, irrelevant here)
- the middle one is a JLabel wrapped in a JScrollPane
- the bottom one is a JTable also wrapped in a JScrollPane
The applet retrieves from the web the image (which is displayed in the
top panel) and a "region file" (a list of sky positions with associated
a shape, circle, box, ellipse etc. and other info). The region file is
loaded in the bottom JTable, and displayed graphically onto the top
image.
Then I have a mouse adapter which, clicking onto the image, locates the
nearest region (within a tolerance, otherwise shall issue a "no region"
message). Let's assume that the region is at index "nearest" in the
Vector of region records
RegionRecord rr=(RegionRecord) mtm.rrs.elementAt(nearest)
On a successful click, I hilight the row associated to the nearest
record in the JTable mytable. To do this I do
mytable.changeSelection(nearest,0,false,false)
(or mytable.clearSelection() if no region is located). This
automatically scrolls the Jtable up or down to put the hilighted region
row in sight.
At the same time, on each click I write a message to the middle panel,
via a method which ultimately does
msg.setText(msg.getText()+"<br>"+mymessage) ;
where msg is the Jlabel in the middle panel. This is followed by a
repaint of the overarching applet content pane.
The point is that, once the panel is full, a scrollbar appears, but the
(added) bottom line is no longer on the screen (the scroll bar has to be
scrolled manually).
I tried playing with msg.setVerticalAlignment() to TOP or BOTTOM but it
seems to have no effect once the scrollbar appears.
How do I force the JLabel wrapped in the JScrollPane to automatically
scroll to the last line added ?
(BTW the reason I used a JLabel instead of a JTextArea is in order to be
use HTML tags to format differently errors, warnings and info messages).