JEditorPane always scrolls down to the bottom, how can I prevent this?
Hello, I have the following code that contains a JTable and JEditorPane in a panel. When I click on a headline on the table, I have some text showing up in the lower pane. My problem is that the lower pane (that is inside a JScrollPane) always scrolls down to the end of the text, but I want to to always point to the beginning.
Does anyone know how to do this?
Your help will be appreciated.
Thanks!
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
public class MyHTMLPaneTest {
JFrame frame;
JPanel panel;
JSplitPane splitPane;
JTable table;
JEditorPane htmlPane;
JPanel tablePanel;
DefaultTableModel model;
JViewport viewPort;
public MyHTMLPaneTest()
frame = new JFrame("MyCalHTMLPane Test");
panel = new JPanel(new BorderLayout());
splitPane = new JSplitPane();
tablePanel = new JPanel(new BorderLayout());
setTable();
tablePanel.add(table.getTableHeader(), BorderLayout.NORTH);
tablePanel.add(table, BorderLayout.CENTER);
htmlPane = new HTMLPane();
JScrollPane pane = new JScrollPane(htmlPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
viewPort = pane.getViewport();
viewPort.setViewPosition(new Point(0, 0));
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tablePanel, pane);
panel.add(splitPane, BorderLayout.CENTER);
frame.getContentPane().add(panel);
frame.setSize(new Dimension(400, 300));
frame.setVisible(true);
public void setTable()
String[] columnNames = {"Date","Time","Subject"};
Object[][] data =
{"03/31/05", "8:20 AM EDT", "Headline 1"},
{"08/24/05", "8:19 AM EDT", "Headline 2"},
{"08/18/05", "8:18 AM EDT", "Headline 3"},
{"08/12/05", "8:17 AM EDT", "Headline 4"},
{"06/20/05", "8:16 AM EDT", "Headline 5"},
{"06/20/05", "8:15 AM EDT", "Headline 6"}
model = new DefaultTableModel(data, columnNames);
table = new JTable(model);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener()
public void valueChanged(ListSelectionEvent e)
String text = "LOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOOOOOOONG" +
"\nLOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOONG"+
"\nLOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"+
"\nSTRIIIIIIIIIIIIIIIII" +
"\nIIIIIIIIIIIIIIIIIIII" +
"\nIIIIIIIIIIIIIIIIIIIII" +
"\nIIIIIIIIIIIIIIIIIIIII" +
"\nIIIIIIIIIIIIIIIIIIIIING"+
"LOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOOOOOOONG" +
"\nLOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOONG"+
"\nLOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOO" +
"\nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"+
"\nSTRIIIIIIIIIIIIIIIII" +
"\nIIIIIIIIIIIIIIIIIIII" +
"\nIIIIIIIIIIIIIIIIIIIII" +
"\nIIIIIIIIIIIIIIIIIIIII" +
"\nIIIIIIIIIIIIIIIIIIIIING";
htmlPane.setText(text);
public static void main(String[] args) {
MyHTMLPaneTest test = new MyHTMLPaneTest();
}
try setCaretPosition:
table.getSelectionModel().addListSelectionListener(
new ListSelectionListener()
public void valueChanged(ListSelectionEvent e)
String text = "LOOOOOOOOOOOOOOOOOOO"
+ "\nOOOOOOOOOOOO"
+ "\nOOOOOOOOOOOOOOOO"
+ "\nOOOOOOOOOOOOOOOO"
+ "\nIIIIIIIIIIIIIIIIIIIII"
+ "\nIIIIIIIIIIIIIIIIIIIIING";
htmlPane.setText(text);
htmlPane.setCaretPosition(0); // ******* here **********
});
Similar Messages
-
I have an Ipod Touch 5th gen and I'm running Windows Vista 32-bit Home Premium. Unfortunately, everytime I plug in my ipod, my screen resolution changes and i go down to an 8 bit from 32...on its own. I can I prevent this from happening every time I plug it in to my pc?
All I can suggest is:
Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7
http://support.apple.com/kb/HT1923
http://support.apple.com/kb/HT1923Seems it is a windows problem.
You can also try rolling back the driver for your video card. -
I can use Firefox for a page or two, then I realize the phone has frozen completely. This seems to happen especially if I've lauched Firefox through a link in another application. The Droid X battery is very hard for me to pop out, but I've had to do it several times and so have gone back to Dolphin browser for the time being.
I'm having the same problem with the official Firefox 4 release.
I'm not on the Droid X though, I'm on a Samsung Galaxy S phone (Vibrant) running Froyo.
It is very easy to replicate, I keep trying to use firefox (because I like it), but my phone locks up pretty quickly every time. -
Hi! My photos are great but are received upside down... How can I prevent this from happening? Thanks!
I have iPad 2 and I am having same problem since I updated to iOS 5. All we can do it is rotate it from computer
-
Yahoo Mail scrolls down to the bottom of the page every time I am in my inbox
For the last couple of months, every time I use my Yahoo Mail account, the page automatically scrolls down to the bottom, forcing me to scroll back to the top to see my e-mail. It sounds very minor, but over time, it has become extremely irritating. I know this is a Firefox issue, because I do not experience this problem when checking my Yahoo Mail using IE or Chrome. Please let me know the fix ASAP so I don't lose my sanity.
Open Image Capture. In the bottom left corner you will see a triangle symbol as shown below. Press this to see the view shown and here you will see the drop menu that determines what happens when you connect your iPad. In the image shown, I have set no application to open when this iPad is connected.
-
Regarding Mail: When I return to my computer after it has gone to sleep, my accounts go offline, and are always asking me for the password. THis is very annoying. How can I prevent this?
Back up all data.
Launch the Keychain Access application in any of the following ways:
☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
☞ Open LaunchPad. Click Utilities, then Keychain Access in the icon grid.
Select the login keychain from the list on the left side of the Keychain Access window. If your default keychain has a different name, select that.
If the lock icon in the top left corner of the window shows that the keychain is locked, click to unlock it. You'll be prompted for the keychain password, which is the same as your login password, unless you've changed it.
Right-click or control-click the login entry in the list. From the menu that pops up, select Change Settings for Keychain "login". In the sheet that opens, uncheck both boxes, if not already unchecked.
From the menu bar, select
Keychain Access ▹ Preferences ▹ First Aid
If the box marked Keep login keychain unlocked is not checked, check it.
Select
Keychain Access ▹ Keychain First Aid
from the menu bar and repair the keychain. Quit Keychain Access. -
I'm always losing all of my music and get a lot of apps that i don't need when i plug my i4 into my mac. I only ticked the box 'Manually manage music and videos' but it's always syncing itself. How can i prevent this? I don't want to put back 1500 any more because of this. Please Help!!!
I'm always losing all of my music and get a lot of apps that i don't need when i plug my i4 into my mac. I only ticked the box 'Manually manage music and videos' but it's always syncing itself. How can i prevent this? I don't want to put back 1500 any more because of this. Please Help!!!
-
I already have an itunes account on my laptop but have been setup on a mac and have songs that have not been purchased from the itunes store, I cannot get the songs from my iPhone onto my itunes account on the mac. how can I do this?
You copy them from your old computer or your backup copy of your old computer.
The iphone is not a backup/storage device. -
My child accidentally rented a movie on Apple TV. Is there a way to refund the rental if we don't watch it?
How can I prevent this from happening? Is there a way to password protect future purchases?Did you try Parental Controls?
Apple TV: Understanding Restrictions (parental controls) - Apple Support
See if that does the trick: I think there's a way for you to request a password for purchases, but still be logged in. -
I have an ipad and when I watch a video the audio does not match up with the video, how can I fix this?
Hello there, graciecloyd.
The following Knowledge Base article offers a few steps to try when an application is not functioning as expected:
iOS: Understanding multitasking
http://support.apple.com/kb/ht4211
If an app doesn't respond to your input, or doesn't perform as expected, do the following, testing after each step:
Check for app updates.
Force the app to close.
Restart your device.
Update your iOS device.
Learn more about troubleshooting apps.
On Step 2, close all applicaitons that are open. On Step 3, if the restart doesn't help resolve the issue, you may also want to try the Reset step in that article as well.
Thanks for reaching out to Apple Support Communities.
Cheers,
Pedro. -
My mac is freezing all the time, how can I fix this?
My mac is freezing all the time, how can I fix this?
Run Disk Utility to verify/repair your drive(s). Boot from your installer dvd to repair the boot drive. If the repair reports that it fixed anything then see if your problem is fixed.
-
When I delete a file, it does not appear in the Trash - How can I fix this. Its a brand new MacBook Pro 17''
http://www.thexlab.com/faqs/trash.html for starters.
-
Hi I dropped my iphone 5 in water last night, it is working but has shadow over the screen how can I get this fixed?
Probably too late to do anything but replace the device at this point.
Once electronics get wet, the best thing to do is turn it off and put it in silica gels packs or uncooked rice for a minimum of 72hrs. Only then should the user attempt to power the device on. -
My IPAD (original version) is deleting everything over 30 days from my calendar. How can I prevent this and how can I get back the deleted events?
You are most welcome
-
I have photoshop elements 12 and when I use the font tool it crashes the program, how can I fix this?I have a macbook pro
Use the crop tool.
On the tool's option bar, type 300 px & 200 px, and the desired resolution.
Maybe you are looking for
-
Problem while installing adobe photoshop cs6
Hey guys, I have been trying to install adobe photshop CS3 trial version on my MAC. I have the adobe air installed. When I get to adobes webpage to download the trial version i get this message: This application cannot be installed because this insta
-
Activating screen says I'm not connected with internet
Acrobat 10 stopped working - found a solution calling for deactivating CS6 and re-activating. Deactivated fine but when reentering the serial number and then activate.... screen states I am not connected to the internet (and I am). Have tried several
-
Premiere crash down when trying to export Prores - on a mac!
Hi, I have a Mac Book Pro, mid 2010, with Lion, and a new SSD drive. I managed to export 18mn in Apple Prores 422HQ, like the original footage, 2 days ago from Premiere Pro CC 2014. It took a while, around 3 hours, but it worked. Today, when I try to
-
Using Add-SQLAvailabilityDatabase command
Hi All, I'm trying to get the Add-SqlAvailabilityDatabase command working. This is how the command is supposed to be formatted: Add-SqlAvailabilityDatabase -Path "SQLSERVER:\SQL\PrimaryServer\InstanceName\AvailabilityGroups\MyAg" -Database "MyDatabas
-
Export failed, archive corrupt error
Hi - I am getting an Export failed, archive may be corrupt error when I try to export my EAR from Workshop 9.2 MP1. (Oddly enough, if I build my EAR with the exported Ant scripts, that works. I can deploy and run this EAR). An the EAR is truly corrup