Fixed a top line in JScrollPane?

Dear all,
I have a JScrollPane, which has a textPane in it. Now I want to set one important warning line at the top of the textPane, and then add any other texts into textPane following the warning line. Moreover, I want this warning line to be fixed at the top, no matter whether the textPane scroll down or not, i.e, this warning line is always at the top of pane and never disappears when scrolling down the textPane.
I do not know how to implement this. The following code will scroll away the warning line after I adds long lines to it.
Any samples on how to implement this?
public class NewsPane extends JScrollPane {
  private JTextPane text;
  private DefaultStyledDocument doc;
  public NewsPane() {
       JTextPane text = new JTextPane( doc=new DefaultStyledDocument());
       text.setText("Warning ...");
       setViewportView(text);
  }Thanks!

Try this
regards
Stas
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.*;
public class Test {
JTextPane edit=new JTextPane();
JScrollPane scroll;
JLabel l;
public Test() throws Exception {
JFrame frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
scroll=new JScrollPane(edit);
l=new JLabel("Warning!");
l.setBounds(10,10,100,20);
l.setForeground(Color.red);
edit.add(l);
frame.getContentPane().add(scroll);
AdjustmentListener adjLst = new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
Rectangle rect=scroll.getViewport().getViewRect();
l.setLocation(rect.x+10,rect.y+10);
scroll.getVerticalScrollBar().addAdjustmentListener(adjLst);
frame.setSize(200,200);
frame.setLocationRelativeTo(null);
frame.show();
edit.getDocument().insertString(0,"test1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n",null);
public static void main(String[] args) throws Exception {
new Test();

Similar Messages

  • Problem exporting notation from score to PDF in Logic 8. Top line of staff displaced a 1/6th note when exported.

    When I export drum notation from the score to pdf, it shifts the top line of the staff over by a 16th note. It looks the way I want in the program, but only does this when exported. I'm using Logic 8. Anyone know how to fix this? See the pictures attached below...
    Here's a screen shot of the notation in Logic:
    Here's what it looks like when exported to PDF:
    Any help would be appreciated. Thanks!

    I've tried both ways and had the same results. I discovered today though that if I zoom in all the way in the score the notation actually shifts over in Logic. I'm not sure why it does that, but now I know that it has nothing to do with exporting or how I export it. The notes should line up for this particular groove and I've tried with other beats and had the same results. Not sure if there's a setting somewhere that displaces certain lines of the staff or something of that nature. I can drag the notes over with the layout tool, but it'd be nice to have a preset to have it go where I want it and save myself time. Thanks for responding and if you have any other ideas let me know.

  • Placing ScrollBar Back On Top Of The JScrollPane

    Hi....
    Just a tiny problem......I have a problem placing the scrollbar back on top of the JScrollPane after few sentences of words are placed into the JTextArea at once. The JTextArea is within the JScrollPane.
    Does anyone has any idea on how I can position the scrollbar back on top of the JScrollPane after the words are placed into the JTextArea.....???
    Britney

    Just some additional comments for anyone who is searching for this solution in the future (as I was today)...
    Neither of these two lines of code did anything by itself. The scrollbar was left at the bottom of the text area.
    myScrollPane.getVerticalScrollBar().setValue(0);
    myScrollPane.scrollRectToVisible(new Rectangle(0,0,1,1));This line by itself basically worked - the scroll pane was reset to the top so that you could see the top line of text. However, if I had previously scrolled down, the scroll bar was not reset all the way to the top (it was just a tad below the top).
    myTextArea.setCaretPosition(0);To get the scroll pane AND scroll bar to reset to the top, I used BOTH of the following lines of code. This is definitely the best solution I have found:
    myTextArea.setCaretPosition(0);
    myScrollPane.getVerticalScrollBar().setValue(0);Something else I had tried in the past was this:
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            myScrollPane.getViewport().setViewPosition(new Point(0, 0));
    });This worked in that it reset the scroll pane to the top, but you could see it scroll down to the bottom as text was added, and THEN it reset to the top, causing a "flashing" effect.
    Hope this helps anyone struggling with this issue in the future.
    Barb

  • On my iphone 5, "Reminders" App, Top line says" Erinnerrungen". How do I change this to English..

    On my iphone 5, "Reminders" App, Top line says" Erinnerrungen". How do I change this to English..
    I have English listed all throughout my iphone.
    I tried this for a similar problem:
    I've had this problem for months, finally figured out how to fix it!
    Go to https://appleid.apple.com and
    enter your Apple ID and password,
    then go to Language and Contact Preferences
    and type in your correct language.
    My Language was set to "English" for "Preferred Language"
    Please help !!!

    Since that is German, try going into the phone's settings and change the language to German. Turn off the phone and back on. Then change the language back to English.
    KOT

  • Donot want to fix the schedule lines at an Early date even P.O is the creat

    Hi ,
      If a material is sourced via a Scheduling Agreement, then MRP automatically creates schedule lines for this to meet MRP requirements.
    However, if a separate PO is raised for the same material (irrespective of the supplier) at a date after one or more of the scheduling agreement schedule lines, MRP creates a message to reschedule in the PO in front of the schedule lines even if this is known to not be possible. the result is that the schedule lines for standard supply are not put in early enough.
       And We don't  want to fix the schedule lines in a t an early date to over come this.Is there any settings for the same.

    Hello,
    If you want to control MRP messages for rescheduling you can make settings in tcode : OMDW either at plant level or MRP group level.
    You can introduce Tolerance value forward & Tolerance value for displacemt in No. of days here.
    If system finds requiremnts within the tolerance no of days it will not create MRP Exception messages. This way you can avoid unwanted messages.
    Thanks,
    Ram

  • In printing only a specific selected section, the top line or 2 of the printout is not printing. This only happened since the last update. It does not happen when I use internet explorer.

    I read many financial documents during the day. I sometimes print only a selected segment of an article or a financial statement. When I print selected only, the top line or 2 lines is omitted from the print document. It does not happen in explorer.
    I used Firefox for years, and this just started in the last 3 weeks or so. I can get around it by just selecting 2 lines above what I want to print. But, it is annoying.

    * [[Printing a web page]]
    * [[Firefox prints incorrectly]]
    Check and tell if its working.

  • Fix table header line of Query in default web template WAD 7.0

    Dear all,
    I would appreciate if somebody could help me to set parameters to fix the header line of a Web-Item DataProvider (Query) in the default web template 0ANALYSIS_PATTERN for the BEx Web Analyser. I mean I want to see the header line with the characteristics and key figures description even if I scroll down in the query. 
    My idea was to create a second frame in the template and to fill it with the same DataProvider just with the header of the Query. The problem is that the performance of the query would be badder if we load two Dataprovider/Query instead of one.
    Many thanks in advance for your answer and help!!!
    Best regards
    Abdel

    Hi Dion,
    Thank you very much for your answer! I have tried to find a paramter in the web application designer to do that, but without success. Now I have included a new container with the same Analysis Web Item, but it does not function! May you have a better idea??
    Thank you very much in advance for your help. I'll also post my question in a BI-Forum as you suggested. 
    Best Regards
    Abdel

  • I am doing a cover for O.M.G. by usher and it requires 4 to 5 different vocal layers. My first "line" of vocals keeps disappearing even after i save it. So I have to redo everything on the top line. Any help?

    I am doing a cover for O.M.G. by usher and it requires 4 to 5 different vocal layers. My first "line" of vocals keeps disappearing even after i save it. So I have to redo everything on the top line. Any help?

    For what it's worth, you posted this in 2011, and here in 2014 I am still having this same issue. Over the last two days, I have had to unlock my apple account 8 times. I didn't get any new devices. I haven't initiated a password reset. I didn't forget my password. I set up two factor authentication and have been able to do the unlocking with the key and using a code sent to one of my devices. 
    That all works.
    It's this having to unlock my account every time I go to use any of my devices. And I have many: iMac, iPad, iPad2, iPad mini, iPhone 5s, iPod touch (daughter), and my old iPhone 4 being used as an ipod touch now.  They are all synced, and all was working just fine.
    I have initiated an incident with Apple (again) but I know they are just going to suggest I change my Apple ID. It's a simple one, and one that I am sure others think is theirs. I don't want to change it. I shouldn't have to. Apple should be able to tell me who is trying to use it, or at least from where.
    Thanks for listening,
    Melissa

  • Safari will not load completely, just the top line

    safari will not open completely, just the top line appears. I have an Imac oper at 10.5.8

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of the test is to determine whether the problem is caused by third-party software that loads automatically at startup or login, by a peripheral device, by a font conflict, or by corruption of the file system or of certain system caches.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards, if applicable. Start up in safe mode and log in to the account with the problem. You must hold down the shift key twice: once when you turn on the computer, and again when you log in.
    Note: If FileVault is enabled in OS X 10.9 or earlier, or if a firmware password is set, or if the startup volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to start up and run than normal, with limited graphics performance, and some things won’t work at all, including sound output and Wi-Fi on certain models. The next normal startup may also be somewhat slow.
    The login screen appears even if you usually login automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem?
    After testing, restart as usual (not in safe mode) and verify that you still have the problem. Post the results of the test.

  • I only print the top line and bottom line, content in middle doesn't print

    When I print an email only the very top line at the top of the page prints and the very bottom line at the very bottom of the page print. For example the bottom line says page 1 of 1 and then on the other side the date and time. Top line has the web address. When I open internet explorer and print and email I have no problems. This just started out of the blue a few updates ago.

    If there isn't a Page Setup in the Print Dialog, open Text Edit>Edit>Page Setup, check borders there or use Custom Page setup & save.

  • Top line suddenly missing from display - where did it go?  how can I get it back?  Don't have finder, time and date, options...

    Top line is suddenly missing:  no finder, no options, no date and time or wifi status, no time capsule to return to previous settings!  Can't figure out what happened.

    You can only sync with one computer. When you synced to the new computer it would have erased it and synced what was on the new computer.
    You always need to have a backup, an iPhone is not a storage device.
    When you get a new computer you need to transfer your library before syncing
    If you don't have a backup you may be out of luck
    The only thing would be if you're in the US and have access to the iCloud beta to reload purchases
    http://support.apple.com/kb/ht2519

  • How do you fix a fine line scrolling on the screen of all apps ex wallpaper, email,safari,word?

    How do you fix a fine line scrolling on all screens - ex wallpaper,email,safari,word etc?

    You may have a hardware  problem, however I'd start by restarting in Safe Mode and if that doesn't fix it I'd recommend running Apple Hardware Test in Extended Mode about 2-3 times to see if any errors come up.

  • Mail info panel top line does not show subject or from subsequent lines do.

    mail info panel top line does not show subject or from, subsequent lines do.

    DOrk4L,
    Have you tried re-calibrating the battery? To re-calibrate it, let the battery drain completely and then charge it fully. You should see correct battery usage after that.
    Hope this helps,
    Jennifer B.

  • My toolbar will only open when I press alt and then only the top line

    the complete top toolbar is not visable on any web page. to use file print history or bookmark I have to press ALT. the top line then disapears when a website is chosen. I then have to repeat this for every bookmark choice.

    Your above posted system details show outdated plugin(s) with known security and stability risks.
    # Shockwave Flash 10.0 r42
    # Java Plug-in 1.6.0_13 for Netscape Navigator (DLL Helper)
    Update the [[Managing the Flash plugin|Flash]] plugin to the latest version.
    *http://www.adobe.com/software/flash/about/
    Update the [[Java]] plugin to the latest version.
    *http://java.sun.com/javase/downloads/index.jsp (Java Platform: Download JRE)

  • Premiere cc 2014 with mac pro top line of mac

    I have mac pro top line of mac 12 gb memory 3,7 processor  quad intel xeon and the workflow is terrible, seen vídeo as 1/4, I`m just using memory to performance, there`s some way to see the video

    Moving to Premiere Pro forum... and some links that MAY help
    10.9.3 links
    -next link says After Effects, but check YOUR permissions !!!
    -http://blogs.adobe.com/aftereffects/2014/06/permissions-mac-os-start-adobe-applications.ht ml
    -Mac 10.9.3 workaround https://forums.adobe.com/thread/1489922
    -more Mac 10.9.3 https://forums.adobe.com/thread/1491469
    -and https://forums.adobe.com/thread/1507936
    -Enable Mac Root User https://forums.adobe.com/thread/1156604
    -more Root User http://forums.adobe.com/thread/879931
    -and more root user http://forums.adobe.com/thread/940869?tstart=0

Maybe you are looking for