Subclassing JTextArea, but i cannot make it scroll

The origin of my problem was that i wanted to make a text editor with a linecount on the left. I found a class on the internet which subclassed jpanel and added a scrollpane and a jtextpane into the panel, and overrid the paint() method in the JTextPane. I changed it to inherit from jtextarea to avoid rewriting all of the methods for editing and getting info from the JTextArea. It seems to work just fine, except for the scrolling, which i cannot get to work at all..
The new class is pasted here: http://pastebin.com/m236b79c9
And the clientclass is here: http://pastebin.com/m2f8199db
I can see three posible solutions:
1. make it work something like the way i have tried before. Perhaps the methods from Scrollable messes it all up?
2. I go back to a previous version where JPanel was the superclass, and write the methods i need to edit and get info from the JTextArea
3. Like #2, except I keep the JTextArea public and access it when needed for, and only write the methods that will be used the most.
#1 is preferable, if not, #2 or #3 is ok..
Gratefull for all help!

Ok, I merged the two classes above to make it small..
The code is here:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Point;
import javax.accessibility.AccessibleContext;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.text.Document;
import javax.swing.text.BadLocationException;
* @author Torstein
* @author Daniel Sjöblom
public class JNumberedTextArea2 extends JTextArea {
    private final static String uiClassID = "NumberedTextArea2UI";
    JScrollPane scrollPane;
    public JNumberedTextArea2() {
        this(null, null);
     * Constructs a new <code>JNumberedTextArea</code> with the text in
     * the JTextArea
     * @param text the text is added to the JTextArea
    public JNumberedTextArea2(String text, JScrollPane scrollPane) {
        super(text);
        setMinimumSize(new Dimension(30, 30));
        setPreferredSize(new Dimension(30, 30));
        setMinimumSize(new Dimension(30, 30));
        this.scrollPane = scrollPane;
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        int charWidth = g.getFontMetrics(this.getFont()).charWidth('0');
        int antDigits = (int) Math.log10(this.getLineCount()) + 1;
        Insets margin = this.getMargin();
        margin.left = (charWidth * antDigits + 3);
        margin.top = 0;
        this.setMargin(margin);
        int start = this.viewToModel(scrollPane.getViewport().getViewPosition());
        int end = this.viewToModel(new Point(
                scrollPane.getViewport().getViewPosition().x + this.getWidth(),
                scrollPane.getViewport().getViewPosition().y + this.getHeight()
        Document doc = this.getDocument();
        int startline = doc.getDefaultRootElement().getElementIndex(start) + 1;
        int endline = doc.getDefaultRootElement().getElementIndex(end) + 1;
        int fontheight = g.getFontMetrics(this.getFont()).getHeight();
        int fontdesc = g.getFontMetrics(this.getFont()).getDescent();
        int starting_y = -1;
        try {
            starting_y = this.modelToView(start).y -
                    scrollPane.getViewport().getViewPosition().y + fontheight - fontdesc;
        } catch(BadLocationException e1) {
            e1.printStackTrace();
        for(int line = startline, y = starting_y; line <= endline; y += fontheight, line++) {
            g.drawString(Integer.toString(line) + ":", 0, y);
        this.repaint();
    public static void main(String[] args) {
      JFrame frame = new JFrame("JNumberedTextArea2");
      Container contPane = frame.getContentPane();
      JTabbedPane tabbedPane = new JTabbedPane();
      JScrollPane scrollPane = new JScrollPane();
      JNumberedTextArea2 textArea = new JNumberedTextArea2("This is a string\nit contains several lines\nindeed", scrollPane);
      scrollPane.setViewportView(textArea);
      tabbedPane.addTab("textArea", scrollPane);
      contPane.add(tabbedPane);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setSize(new Dimension(400, 400));
      frame.setVisible(true);
}

Similar Messages

  • Dropdown dialog boxes will not work. I can click on the boxes, the dropdown appears, but I cannot make anything in the box operate. I just upgraded to 6.0.2 on a fresh install of Windows XP

    I use the net to pay bills. The dialog box on my bills have accounts in them, but I cannot make the account numbers work. I regularly go to websites that are several pages deep, but the dropdowns for the next page don't work. The numbers, as well as the accounts appear, but they cannot be highlighted to access them.

    I'm not sure if the crash is or isn't related to fonts.
    Deciphering the crash long is something I don't have any experience with.
    I'm not even sure how the crash log is structured. I've downloaded two screen captures: one from the top of the adobe Photoshop crash log and one from the bottom. Perhaps someone more knowledgeable than I can discern what may be causing the crash?
    Screen capture from the top of the Adobe Photoshop crash log:
    Screen capture from the bottom of the Adobe Photoshop crash log:
    Any ideas?
    Thanks a bunch.

  • I have the doc on my screen as an adobe  but I cannot make changes?  The browser does not locate it?

    I have the doc on my screen as an adobe  but I cannot make changes?  The browser does not locate it?

    Hi,
    Are you opening a PDF file in browser and trying to edit the PDF file there?
    Please let me know in more details.
    In general most PDF files cannot be edited in browser and some PDF can be edited with the permission for editing in browsers.
    Thank you.
    Hisami

  • I Can sign to the app store normally but i cannot make download from it on my iPhone 4s

    Hello
    I Can sign to the app store normally but i cannot make any download from it on my iPhone 4s
    Any body can help … please

    Welcome to Apple Support Communities
    First, when you are going to turn off or restart your Mac, you will see a box called "Reopen windows when logging back in" in the shutdown or restart window. Untick this box and see if the App Store opens automatically in the next startup.
    If it starts, open System Preferences > Users and Groups > Login Items, and see if the App Store shows up. If so, remove it from this list

  • Firefox is minimized but I cannot make it visible again.

    Firefox is not hanged. I just cannot see it. Right clicking the icon in taskbar I can open a new Firefox window and work in that, but I cannot open the first window with several tabs in it.
    If I close the second window, the first window stays open. Only way to close it, is by taskmanager. Next time I open Firefox it stays hidden.
    If I in a new window I try to open a webpage I know is open in a tab in the first window, I get the question if I want to switch to it. I do, but I still don't see it.
    With alt-tab I can see Firefox is running, but I cannot switch to it. So I know it is open.
    I have tried closing all "plugin-container.exe" in task manager, to no effect.
    Firefox take 200Mb of RAM. Normal.

    I found a workaround that solved it, though I still don't know the cause.
    Right clicking the Firefox icon in taskbar doesn't give the option to maximize the window, but I realized that holding the mouse over it, I get a preview of the window (empty, shows only menubar). Right clicking on this preview, I do get maximize. And now I CAN see the window.
    But there is still a bug somewhere. If I click "restore down" the window disappears again.
    The workaround I found was this:
    - Maximize the first window (with 8 tabs).
    - Open a second window.
    - Pull all tabs to second window.
    - When the last tab is pulled, the first window is automatically closed and removed.
    The new window seems to work normal. (I'm writing this...)

  • TS2621 Have tried everything to get mail on my I phone 5 but still cannot make it happen no matter we try.  Any ideas or do I just give the phone back

    Can anyone let me know how to make my I phone 5 send receive e-mails on pop 3
    Have been in touch with all the right people and there end nothing wrong my I phone 4s will receive but not send now this one will not do anything
    No good for my work

    With an existing ID, you either have to have a credit card, or redeem an itunes gift card. The only way to create an Apple ID without a credit card, is to follow the directions here, EXACTLY:
    http://support.apple.com/kb/HT2534

  • Within the Sendible, I cannot copy and paste links (when not hyperlinked). The help info indicated it was connected to a Mozilla profile issue. But I cannot make these changes on my own. Please help! PKennedy

    Mozilla will not allow me to copy and paste a URL from Sendible. The info indicated I had to update my profile information, but I'm not able to do this on my own. Please help!

    Clear Cookies & Cache
    * https://support.mozilla.com/en-US/kb/Template:clearCookiesCache
    Clear the Network Cache
    * https://support.mozilla.com/en-US/kb/How%20to%20clear%20the%20cache#w_clear-the-cache
    Troubleshooting extensions and themes
    * https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes
    Check and tell if its working.

  • I redeemed a gift card, but I cannot make in app purchases on my iphone. My account balance is $36.94 and I want to make an in app purchase for $0.99. Why is it still asking for credit card info and not letting me purchase?

    I just want to purchase the next level of Candy Crush Saga, haha. Please help!

    If you were instructed to call them, then that's what you should do. They will probably need to verify your identity before helping you with the security question.

  • HT4642 I have an older Imac.  It is running OSX 10.6.8.  We have two new Ipads and wish to open and use a spread sheet developed on the Imac.  Currently I can open the Spread Sheet but cannot make any entries. How can I fix that problem?

    I wish to use Spread Sheets developed on my Imac (OSX 10.6.8 with Numbers 08) on my new Ipad Mini.  Currently they will open but I cannot make entries.
    Is there some software I need to download to my Ipad ?
    If I update my Imac Numbers 08 will it still work with existing spread sheets ?
    If I upgrade my OSX 10.6.8 will it impact my files originated under my old OSX and will all my programs work?
    Is there a work aropund that will allow me to use those Spread Sheets on my Ipad ?
    As informative as Apple is with their products, I see little that addresses compatability issues.  Art they non existant ?
    I hate to make any changes unless I know I am not going to be causig a lot of grief!
    Any assistance would be appreciated.

    On looking at the secure.log on the iMac with OSX10.6.8, I see these entries at each attempt to scp into the iMac:
    Dec 29 11:06:20 molika sshd[7248]: in pam_sm_authenticate(): Failed to determine Kerberos principal name.
    Dec 29 11:06:26 molika sshd[7246]: Accepted keyboard-interactive/pam for prowat from 137.110.243.132 port 35571 ssh2
    Dec 29 11:06:26 molika com.apple.SecurityServer[26]: Session 0x236a14 created
    Dec 29 11:06:26 molika com.apple.SecurityServer[26]: Session 0x236a14 attributes 0x20
    Dec 29 11:06:27 molika com.apple.SecurityServer[26]: Session 0x236a14 dead
    Dec 29 11:06:27 molika com.apple.SecurityServer[26]: Killing auth hosts
    Dec 29 11:06:27 molika com.apple.SecurityServer[26]: Session 0x236a14 destroyed
    I don't know what to make of this.
    Peter R

  • No Verizon Wireless Service/Cannot Make Calls but can connect to 4G LTE & use internet

    I have a Motorola Droid Ultra and my phone just does not catch Verizon Wireless Service anywhere. It shows up as 4GLTE and i can still connect to my data & go on the internet but I cannot make any calls. Ocassionally it will connect to "Verizon" and I can recieve SMS (Text Messages)but still no calls.

        Titah420,
    We definitely want you to have access to all your services. What happens when you try to make a call? Are you able to receive calls? Are text messages an issue?
    SandyS_VZW
    Follow us on Twitter @VZWSupport

  • CSS Template in Dreamweaver, cannot make flash(swf) show ???

    Hi all,
    I'm quite new at using dreamweaver, have been using GoLive
    some before and I have got a time consuming problem:
    To try to get a hang of CSS page designs I've used the Page
    Design (CSS) Halo Right nav that comes with DW8.
    I've learnt pretty much how it works BUT, I cannot make a
    flash file visible when inserted to the page design ????
    It does not show if I insert it to an existing div tag or if
    I insert it in a new layer. What am I doing wrong ?
    (same goes for images)
    Need help quickly.
    Thanks!

    This is one of the several weird problems with the HALO
    layout.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Pasay" <[email protected]> wrote in message
    news:eve7b0$s6g$[email protected]..
    > OK!,
    > will look into that, as I said I'm all new to this,
    grateful for all tips.
    > I've posted a new Topic : CSS Template in Dreamweaver,
    Submeny
    > dissapears?
    > may be related to the javascript error ?
    > //Bosse
    >

  • Payment delivered but still cannot call

    payment delivered but still cannot call. Why?

    Here are some things you can do -
    https://support.skype.com/en/faq/FA50/i-just-purch​ased-skype-credit-but-i-cannot-make-any-calls
    Yet, if still needed, you can also contact customer support for further assistance or instructions. Just open the link pasted below to see the instructions on how to get in touch with customer service -
    https://support.skype.com/en/faq/FA1170/how-can-i-​contact-skype-customer-service
    IF YOU FOUND OUR POST USEFUL THEN PLEASE GIVE "KUDOS". IF IT HELPED TO FIX YOUR ISSUE PLEASE MARK IT AS A "SOLUTION" TO HELP OTHERS. THANKS!
    ALTERNATIVE SKYPE DOWNLOAD LINKS | HOW TO RECORD SKYPE VIDEO CALLS | HOW TO HANDLE SUSPICIOS CALLS AND MESSAGES

  • Purchase the order, sign out-in, still cannot make...

    purchased this order (****************693) on April 27, tried to sing out and in several times on May 3. even changed the password, but still cannot make calls, land and mobile. any suggestions?

    Doing that to me too, and only just discovered what its up to. Very annoying, I've had several people assume I am being rude and ignoring them, even though I think I am offline and have left my phone elsewhere because I do not expect or want to be contacted! Very poor of Skype to do this, as it never used to.

  • Cannot make international calls

    I just got FIOS tripple play package with unlimited international calling plan but when i try to make a call to Pakistan, message says that calls to that area are blocked.
    Called Verizon tech support and they say that there is nothing wrong with my phone line and there is no block.
    But I cannot make the phone call
    Can someone suggest/help with the solution

    I would call again, or open a chat request.  Make sure you have a couple examples of numbers that you can not call, and ask them to open a long distance repair ticket.  as long as you have no blocks on your account and you have a long distance plan with them, then they should be able to open a repair ticket.  make sure you call and get the EXACT wording of the message that you get when you call pakistan so that you can give it to them. 

  • I cannot make new purchases on Newsstand

    The application does not allow me to make any new purchase. It suddenly stopped recognizing my Apple ID. I can still view old purchases with my Apple ID but I cannot make new ones. This is driving me crazy ! Has anybody come across this and do you know how to overcome the issue ? Thanks.

    Hello, Mcath23. 
    Thank you for visiting Apple Support Communities.
    There are a couple things that I would recommend trying.  Try closing all open applications and power cycle the device.  Next, go through the section labeled Troubleshoot issues on an iPhone, iPad, or iPod touch in the second article below.  If the issue persists, try completely signing out of the iTunes Store on the iOS device and sign back in.  Be sure to test downloading the item in Newsstand after each step.
    iOS: Force an app to close
    http://support.apple.com/kb/ht5137
    Can't connect to the iTunes Store
    http://support.apple.com/kb/ts1368
    iOS: Sign in with a different Apple ID in the iTunes Store, App Store, and iBooks Store
    http://support.apple.com/kb/ht1311
    Cheers,
    Jason H.

Maybe you are looking for

  • Unquoted special character error

    Am reading data from a file and parsing through it using StringTokenizer. I am putting the data into DB2 tables and therefore need to set the integer and fraction count for decimal numbers so they won't abend the program if they are over the DB2 sett

  • Can I use Time Capsule to serve as an external drive with two different iMacs?

    I want to be able to set up Time Capsule to serve as a backup drive for my iMac, as well as my wife's iMac. So that we don't have to use two seperate back-up drives on each computer. Is this possible?

  • Editing TEXT in WORD file.

    Hi, Is it possible to EDIT a text file (word) from FORMS 10g. Let's say I want to FIND and REPLACE text in a word file. Is there any tools or JAVA code that can help me achieve this? Thanks in advance, Marc.

  • How to project the activity of ipad in tv

    Is there any application to connect the ipad to the tv without using apple tv, without cables, using DLNA but not only for watching videos, to see the exactly the same you see in the ipad? The same that you get when  connect  pc with one projector bu

  • Single pages and spreads in alternate layouts

    Hi, I am currently creating an alternate layout for a multipage InDesign document that already contains my print version inside the document. I have an understanding on how to create the alternate layout (for IPad: 1024px X 768px) yet when I create t