Scrollpane question

I'm trying the example in Sun online tutorial about scrollpane (http://java.sun.com/developer/onlineTraining/awt/contents.html#AWTScrollPane), but i get the image canvas draw inside the scrollpane with the scrollbars, but the scrollbars does not works, as if the image in the panel were of lower size, but it's bigger.
The code is:
inside applet init()
setLayout(new BorderLayout());
ScrollPane sp=new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
. Image im=...loads an image...
sp.add(new ImageCanvas(im));
add(sp, BorderLayout.CENTER);
And image canvas is:
class ImageCanvas extends Component {
private Image image;
public ImageCanvas(Image i) {
image = i;
public void paint(Graphics g) {
if (image != null)
g.drawImage(image, 0, 0, this);
As I said, there are scrollbars but they have no bar to move and scroll throgh the picture. I've tried to setSize of scrollPane and/or imagecanvas to a big size but this doesn't change anything.
Were am I wrong?
Thanks in advance.

Solved, with code from another old tutorial from Sun, different from this one, that seems that does not work correctly.

Similar Messages

  • Question about ScrollPane scroll bar

    Hello Everyone,
    Currently I am working in Flash Professional 8. I need to
    customize the scroll bar in the ScrollPane. I figured out how to
    customize the graphics.
    Instead of the lil grey scroll bar that you can drag I want
    it to be an arrow. I made it into an arrow but there appears to be
    some sort of size restriction on it and the arrow I created appears
    distorted. Is there some way I can change this size restriction and
    have the scroll bar be 100 pixels high if I wanted it to be?
    Thanks in advance for any help!

    anybody?

  • Need help! easy question about scrollpane?

    DefaultStyledDocument document = new DefaultStyledDocument();
    JTextPane tp = new JTextPane(document);
    tp.setMargin(new Insets(5,5,5,5));
    JScrollPane tpScrollPane = new JScrollPane();
    tpScrollPane.setBounds(new Rectangle(5,5,100,200));
    tpScrollPane.getViewport().add(tp, null);
    the compile and run are both OK. but i found it quite strange that the vertical scroll bar works well while the horizental scroll bar doesn't work. when the string inputed up to the width, more inputted characters will be showed in a new line. Could anyone have the same experience and know how to solve it?
    any suggestions are appreciated!
    thanks in advance!

    have you tried it using
    tpScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS;

  • Design problem(split pane scrollpane Insets)

    hi,
    doing a exam simulator prgm
    design is like,
    Question (text area with scrollpane)
    Answers (checkbox inside panel with scrollpane)
    used split pane between qst and ans but big thick bar comes how to reduce size and it is not
    moving.
    used GridLayout for container and panel.
    PROBLEM is how to leave space qst textarea appears from very left edge of screen how to leave some space
    same prblm for checkbox they to appear extreme left on screen.

    Put those components in a JPanel overwriting the getInsets() method like this:
    JPanel cPane=new JPanel(){
        private final Insets _insets=new Insets(10,10,10,10);
        public Insets getInsets(){
            return _insets;
    };...should do the trick, take a look at the Insets class if you need information on how defining it...

  • How can i make my scrollpane in a way that at the opening of a frame it doe

    How can i make my scrollpane in a way that at the opening of a frame it does not scroll down automatically?
    code is below
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.net.*;
    import javax.swing.JOptionPane.*;
    import java.io.*;
    import javax.swing.colorchooser.*;
    import javax.swing.filechooser.*;
    import javax.accessibility.*;
    import javax.swing.border.*;
    import java.sql.*;
    public class Signup extends JFrame
         JLabel p1,p2,p3,p4,p5,p6,uid,upass,cpass,fname,sname,hint,sl,ed,age,adr,cit,zip;
         JTextField uname,fnamet,snamet,hintt,adrt,adrt1,city,zipcode;
         JPasswordField upassw,cpassw;     
         JComboBox sex,education,agegr;
         Signup()
         Container c=getContentPane();
         c.setLayout(null);
         c.setBackground(Color.white);
         /** JPanel c = new JPanel();
         c.setBackground(Color.white);
         int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
         int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
         JScrollPane jsp = new JScrollPane(c, v, h); ***/
    p1=new JLabel("Create Your Icafe!ID",10);
         p2=new JLabel("Personal Information");
         p3=new JLabel("User Address");
         p4=new JLabel("Tell Us About Your Hobbiess (Optional) ");
         p5=new JLabel("Tell us something about what you like. This will help us choose the kind of content to display on           your pages.");
         p6=new JLabel("--------------------------------------------------------------------------------");
    uid=new JLabel("User Id");
         upass=new JLabel("Password");
         cpass=new JLabel("Confirmation Password");
         fname=new JLabel("UserName");
         sname=new JLabel("SurName");
         hint=new JLabel("Hint Question");
    sl=new JLabel("Sex");
         ed=new JLabel("Education");     
         age=new JLabel("Age Group");     
         adr=new JLabel("Address");
    cit=new JLabel("City");
    zip=new JLabel("ZipCode");
         uname=new JTextField(10);
         uname.requestFocus();     
         uname.setToolTipText("UserName");
    upassw=new JPasswordField(10);
         upassw.setToolTipText("Password");
         upassw.setEchoChar('*');
         cpassw=new JPasswordField(10);
         cpassw.setToolTipText("Confirmation Password");
         cpassw.setEchoChar('*');
         fnamet=new JTextField(10);
         fnamet.setToolTipText("FullName");
         snamet=new JTextField(10);
         snamet.setToolTipText("SurName");
         hintt=new JTextField(10);
         hintt.setToolTipText("Hint Question");     
    String[] gender={"[Select one]","Male","Female"};
         sex = new JComboBox(gender);          
    String[] edu={"[Select one]","S.S.C","Inter","Graduate","Post Graduate"};
         education= new JComboBox(edu);     
    String[] ageg={"[Select one]","0 - 15","16 - 35","36 - 70","70 - 100"};
         agegr= new JComboBox(ageg);     
    adrt=new JTextField(15);
         adrt.setToolTipText("Address");
         adrt1=new JTextField(15);
         adrt1.setToolTipText("Address");
         city=new JTextField(15);
         city.setToolTipText("City");
    zipcode=new JTextField(15);
         zipcode.setToolTipText("ZipCode");
         p1.setBounds(200,70,160,30);
         uid.setBounds(350,100,160,30);
         uname.setBounds(400,100,160,30);
         upass.setBounds(335,140,160,30);
         upassw.setBounds(400,140,160,30);
         cpass.setBounds(260,180,160,30);
         cpassw.setBounds(400,180,160,30);
         p2.setBounds(200,220,160,30);
         fname.setBounds(330,260,160,30);
         fnamet.setBounds(400,260,160,30);
         sname.setBounds(335,300,160,30);
         snamet.setBounds(400,300,160,30);
    hint.setBounds(315,340,160,30);     
    hintt.setBounds(400,340,160,30);
         sl.setBounds(370,380,160,30);     
         sex.setBounds(400,380,160,30);
         ed.setBounds(335,420,160,30);     
         education.setBounds(400,420,160,30);
    age.setBounds(330,460,160,30);
    agegr.setBounds(400,460,160,30);
    p3.setBounds(200,500,160,30);
         adr.setBounds(340,540,160,30);
         adrt.setBounds(400,540,160,30);
         adrt1.setBounds(400,580,160,30);
         cit.setBounds(370,620,160,30);
         city.setBounds(400,620,160,30);
    zip.setBounds(590,620,160,30);
    zipcode.setBounds(640,620,160,30);
         Font font = new Font("SansSerif",Font.BOLD, 12);
         setFont(font);
         c.add(p1);
    c.add(uid);
         c.add(uname);     
         c.add(upass);
         c.add(upassw);
    c.add(cpass);
         c.add(cpassw);
    c.add(p2);
    c.add(fname);     
         c.add(fnamet);
    c.add(sname);
    c.add(snamet);
         c.add(hint);
    c.add(hintt);     
    c.add(sl);
    c.add(sex);
    c.add(ed);
         c.add(education);
    c.add(age);
         c.add(agegr);
    c.add(p3);
    c.add(adr);
         c.add(adrt);
         c.add(adrt1);
    c.add(cit);
    c.add(city);
    c.add(zip);
    c.add(zipcode);
         setResizable(false);
         //int a=DO_NOTHING_ON_CLOSE;
         //setDefaultCloseOperation(a);
         show();
         setSize(800,500);
    // Border raisedBorder = new BevelBorder(BevelBorder.RAISED);     
         setContentPane(c);     
    public static void main (String arg[])
         try{
         UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
         }catch(Exception s)
         Signup swu=new Signup();

    just try the following:
    jsp.getVerticalScrollbar().setValue(0);after inserting and adding all your components. this will set the vertical scrollbar up to the very first line.
    regards

  • JScrollPane questions

    Hi, I have two questions regarding JScrollPane:
    1) I have a JPanel inside a scrollpane, but setViewportView() doesn't seem to work too well. Could anyone give me a better idea how to set the viewport view, an example perhaps? The tutorial doesn't go into much detail. For instance, let's say I have an 800 * 600 JPanel with a spot on it at 500, 300. How would I make the JScrollPane move so that this spot is in the centre?
    2) Is there a method that essentially does the same thing as clicking on one of the scrollbar arrows, so I can have four buttons (Up Down Left Right) that scroll instead of scrollbars?
    Thanks.

    #1
    sp.getViewport().scrollRectToVisible(...)
    import javax.swing.*;
    import java.awt.*;
    class Testing extends JFrame
      public Testing()
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel panel = new JPanel(null);
        panel.setPreferredSize(new Dimension(800,600));
        JLabel label = new JLabel("Hello World");
        label.setBounds(500,300,80,20);
        panel.add(label);
        JScrollPane sp = new JScrollPane (panel);
        sp.setPreferredSize(new Dimension(200,200));
        getContentPane().add(sp);
        pack();
        sp.getViewport().scrollRectToVisible(new Rectangle(440,210,200,200));//<-----------------------
      public static void main(String[] args){new Testing().setVisible(true);}
    }#2
    you can get the scrollbar object/s from the scrollpane and use setValue()
    you can set the scrollbar's policy as NEVER - look up the various constructors
    for JScrollpane

  • Question about using scrollRectToVisible?

    hello all:
    From the java doc, it says that
    "void scrollRectToVisible(Rectangle)
    (in JComponent) If the component is in a container that supports scrolling, such as a scroll pane, then calling this method scrolls the scroll pane such that the specified rectangle is visible. "
    I have a small program with the following code:
    jScrollPane1.getViewport().add(bar); // bar is a subclass of JComponent
    // bar.scrollRectToVisible(new Rectangle(0, 0, 430, 50));
    bar.setPreferredSize(new Dimension(430, 50));
    When the size of bar changed, I only need to reset the PreferredSize of bar, then
    the ScrollPane will resize correctly.
    My question is: where should i use scrollRectToVisible?
    thank you
    -Daniel

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ScrollingToView {
      public static void main(String[] args) {
        final JPanel panel = new JPanel(new GridBagLayout());
        final GridBagConstraints gbc = new GridBagConstraints();
        gbc.weighty = 1.0;
        gbc.insets = new Insets(10,0,10,0);
        gbc.gridwidth = gbc.REMAINDER;
        JButton addButton = new JButton("add button");
        ActionListener l = new ActionListener() {
          int buttonCount = 0;
          public void actionPerformed(ActionEvent e) {
            JButton button = new JButton("Button " + ++buttonCount);
            panel.add(button, gbc);
            panel.revalidate();
        addButton.addActionListener(l);
        panel.addComponentListener(new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            Component[] components = panel.getComponents();
            if(components.length > 0) {
              Component component = components[components.length-1];
              Rectangle r = component.getBounds();
              r.y += gbc.insets.bottom;
              //System.out.println("r = " + r);
              panel.scrollRectToVisible(r);
        JPanel northPanel = new JPanel();
        northPanel.add(addButton);
        JFrame f= new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(northPanel, "North");
        f.getContentPane().add(new JScrollPane(panel));
        f.setSize(400,300);
        f.setLocation(400,300);
        f.setVisible(true);
    }

  • Scrollpane, ScrollDrag and buttons

    I think I already know the answer to this question but I thought I'd ask just to be sure. 
    I have a scollpane loaded and I have buttons in the content( a map) thats loaded in the scrollpane.  The buttons work fine until I try to turn on scrolldrag.  So my question: Is there any way to use scrolldrag in a scrollpane when there are buttons in the content?  Or are we stuck with the scroll bars?
    I saw one movie that was done in action script 1 using a scrollpane, with buttons and scrolldrag and the buttons worked. 
    Any help would be appreciated.  I've googled this issue and can't find an answer. 
    thanks.

    Is there any other way to get the scrolldrag functionality and still have the links function?

  • Making an existing component to wear a scrollpane

    I don't want to have a scrollpane. I just want TheComponent that wears a scrollpane. For example, I want to put a scrollpane on the editor component of a combobox. Or more generically and as a related question, how could we write a class extending C, of which object is C in OOP parlance, that has a scrollpane put on it?
    Is it an impossible dream in current Swing?

    you should be able to create a custom editor that uses a JScrollPane containing a JTextFieldAnd I'm afraid we are not. Here's another failure:
    import javax.swing.plaf.metal.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ScrollingComboBoxEditor extends MetalComboBoxEditor{
      JScrollPane jsc;
      JTextField jtf;
      public ScrollingComboBoxEditor(JScrollPane js){
        jsc = js;
        jtf = (JTextField)(js.getViewport().getView());
      public JTextField createEditorComponent(){
        return jtf;
      public Component getEditorComponent(){
        return jsc;
      public Object getItem(){
        return jtf.getText();
      public void selectAll(){
        jtf.selectAll();
      public void setItem(Object anObject){
        jtf.setText((String)anObject);
      public static void main(String[] args){
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JTextField jtf = new JTextField(20);
        JScrollPane jsp = new JScrollPane
         (jtf,  JScrollPane.VERTICAL_SCROLLBAR_NEVER,
          JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        final JComboBox jcb
          = new JComboBox(new String[]{"alpha", "beta", "gamma"});
        jcb.setEditor(new ScrollingComboBoxEditor(jsp));
        jcb.setEditable(true);
        jcb.configureEditor(jcb.getEditor(),
            "alonglonglonglonglonglonglonglonglonglonglongonelinetext");
        jcb.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
            String newSelection = (String)jcb.getSelectedItem();
            jcb.addItem(newSelection);
        frame.getContentPane().add(jcb, java.awt.BorderLayout.NORTH);
        frame.pack();
        frame.setVisible(true);
    }

  • Preloader for a scrollPane?

    hey all,
    i'm loading a large (250k) movie into a scrollPane, and am
    having serious issues trying to get a preloader to work in any
    fashion. i've tried placing the preloader in the root level, but
    the scrollpane forces the 250k to export on first frame to be
    functional, thus making the preloader useless. i tries also to put
    a preloader into the loaded 250k movie, but that made no
    difference. is there a way around this, or are users just going to
    have to wait on faith for the blank scrollpane to populate itself?
    thanks,
    morgan

    once again, i answer my own question. i found out that the
    preloader wasn't working because the inherent nature of "Export for
    ActionScript" necessary for amking a movie loadable into a
    ScrollPane loads that content at the very beginning. if you go into
    the publish settings for the Flash output and click on the Settings
    button next to the ActionScript Version selector, you can set which
    frame of the movie you want to expert frames for classes to. set
    this to frame 3 (most preloaders take up the first two frames), and
    suddenly the preloader functions fine.

  • XML loader in custom Scrollpane

    I'm working on my first website, and have mostly been using tutorials on Lynda.com which has been hugely helpful.  I need several different scrollpanes in the site, one of which is a typical thumbnail gallery that uses XML to load the thumbnail images and displays full-size images & text when thumbnails are clicked.  With a Lynda tutorial I was able to write the appropriate code and use the canned scrollpane in Flash, but even after changing some of the properties I really don't like how it looks.  I found another tutorial (http://www.developphp.com/Flash_tutorials/show_tutorial.php?tid=265) that shows a scrollpane I like better (after some modifications), and I've got it working perfectly elsewhere on the site.. but I'm wondering if/how I can integrate the XML code I've already written into this new scrollpane so I can replace the canned one?  If anyone has any tips or can give me any advice I'd really appreciate it.. 
    Thank you!
    I'm using Flash CS4/AS3
    Macbook Pro
    This is the code for the canned one with all the XML:
    var titleArray:Array = new Array();
    var descriptionArray:Array = new Array();
    var largeimageArray:Array = new Array();
    var thumbimageArray:Array = new Array();
    var imageNum:Number=0;
    var totalImages:Number;
    //xml
    //load xml
    var XMLURLLoader:URLLoader = new URLLoader();
    XMLURLLoader.load(new URLRequest("insituportfolio/mainInSituGallery.xml"));
    XMLURLLoader.addEventListener(Event.COMPLETE, processXML);
    function processXML(event:Event):void {
    var theXMLData:XML=new XML(XMLURLLoader.data);
    totalImages=theXMLData.title.length();
    for (var i:Number = 0; i < totalImages; i++) {
    titleArray.push(theXMLData.title[i]);
    descriptionArray.push(theXMLData.description[i]);
    largeimageArray.push(theXMLData.largeimage[i]);
    thumbimageArray.push(theXMLData.thumbimage[i]);
    loadThumbnail();
    mainScrollPane.source=thumbsMain;
    // load thumbs
    function loadThumbnail():void {
    trace(imageNum);
    var thumbLoader:Loader = new Loader();
    thumbLoader.load(new URLRequest(thumbimageArray[imageNum]));
    thumbLoader.y = 100*imageNum;
    var thislargeimage:String = largeimageArray[imageNum];
    var thistitle:String = titleArray[imageNum];
    var thisdescription:String = descriptionArray[imageNum];
    thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
    function thumbLoaded(event:Event):void {
    thumbsMain.addChild(thumbLoader);
    thumbsMain.buttonMode=true;
    mainScrollPane.update();
    thumbLoader.addEventListener(MouseEvent.CLICK,loadMainImage1);
    function loadMainImage1(event:MouseEvent):void {
    largeUILoader.source=thislargeimage;
    selectedTitle.text=thistitle;
    selectedDescrip.text=thisdescription;
    //add to imageNum (1);
    imageNum++;
    if (imageNum<totalImages){
    loadThumbnail();
    And this is the code for the Scrollpane I'd like to use:
    // Scroll My Content function - AS3
    function scrollMyContent () {
    // Cache the TextField as a bitmap to improve performance.
        content_mc.cacheAsBitmap = true;
    // Event Listeners
    scrollDragger.addEventListener(MouseEvent.MOUSE_DOWN, scrollDraggerPress);
    stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpOnStage);
    // Set variables
    var scrollbarHeight:Number = scrollbarBG.height;
    var contentHeight:Number = content_mc.height;
    var scrollDraggerHeight:Number = scrollDragger.height;
    var maskHeight:Number = contentMask.height;
    var scrollAmout:Number = (contentHeight-maskHeight)/(scrollbarHeight-scrollDraggerHeight);
    var topBound:Number = scrollbarBG.y;
    var bottomBound:Number = scrollbarBG.height-scrollDraggerHeight+scrollbarBG.y;
    var startPos:Number = content_mc.y;
    var leftBound:Number = scrollbarBG.x;
    var absNumSet:Number = 0;
        // When scrollDragger gets pressed we do this
    function scrollDraggerPress(event:MouseEvent):void {
            // Set bounds using some of the scroller BG properties claimed above
    var bounds:Rectangle = new Rectangle(leftBound, topBound, 0, bottomBound);
    scrollDragger.startDrag(false, bounds);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, reportStageMouse);
    function reportStageMouse(event:MouseEvent):void {
    absNumSet = Math.abs(scrollbarBG.y - scrollDragger.y);
    content_mc.y = Math.round(absNumSet * - 1 * scrollAmout + startPos);
    // When mouse is released while dragging we do this
    function mouseUpOnStage(event:MouseEvent):void {
    stopDrag();
    scrollMyContent();

    Thank you, that's helpful... so if I just swap the source, do I just drop in the code for the xml after?  Or should it go elsewhere?
    I'm sorry, I realize this is probably a very basic question.

  • XML/XPath question--how to select a range of elements with XPath?

    Hi there,
    I have an XML DOM in memory. I need to do hold it and issue only parts of it to my client app in "pages". Each page would be a self-contained XML doc, but would be a subset of the original doc. So for instance the first page is top-level elements 1-5. 2nd page would be 6-10 etc. Is this solution best solved with XPath? If not, what's the best way? If so, I have the following question:
    Is there a way to use XPath to select a range of nodes based on position within the document? I know I can do an XPath query that will return a single Node based on position. So for example if I wanted the first node in some XML Book Catalog I could do XPathAPI.selectSingleNode(doc, "/Catalog/Book[position()=1]"); I could wrap the previous call in a loop, replacing the numeric literal each time, but that seems horribly inefficient.
    Any ideas? Thanks much in advance!
    Toby Buckley

    Your question is about marking a range of cells. 99% of the code posted has nothing to do with this. If you want to create a simple table for test purposes then just do:
    JTable table = new JTable(10, 5);
    JScrollPane scrollPane = new JScrollPane( table );
    getContentPane().add( scrollPane );
    In three line of code you have a simple demo program.
    When I leave the mouse button again, these bunch/range of cells shall stay "marked". table.setCellSelectionEnabled( true );
    and I'd like to obtain, say, a vector of a vector containing just those data marked beforeUse the getSelectedRows() and getSelectedColumns() methods for this information. I would suggest you create a Point object to reflect the row/column position and then add the point to an ArrayList.

  • How to create a scrollpane?

    hi to all flash fanatic,
    I need help regarding on how to create a flash scrollpane in
    a full flash site.
    is anybody can give me d exact link of scrollpane sample
    tutorilas or if it's okey can u give me a simple scrollpane sample
    of yours.
    i need it badly.
    many tnx in advnce for ur help
    norma - RP

    I honestly think some of these questions are
    generated by a bot that only responds to answers
    containing actual codeI think we subcontracted a whole company of these.

  • Custom Border painting over scrollpane and toolbar

    I found a LineNumberBorder class in these here forums (I'll post this same question there too) and adapted it to add line numbers to a JTextPane derived class.
    When the border is added to the textpane it paints line numbers to the left of each line in the editor.
    When this composite (textpane and border) is added to a tabbedpane, all is well, unless I switch to another window. When I come back to the editor, the line numbers are being painted beyond the top and/or bottom of the jscrollpane.
    package com.marklawford.editor.textpane;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    * LineNumberBorder.java
    * Created: Wed Aug 25 22:15:12 1999
    * @author Sandip Chitale ([email protected])
    * Copyright 1999. All rights reserved.
    * originally handled text area components
    * adapted by Mark Lawford to accept SyntaxedEditor components which extend JTextPane
    * the getLineStartOffset(int i) method had to be implemented in SyntaxedEditor
    * the int getLineCount() method had to be implemented in SyntaxedEditor
    public class LineNumberBorder extends AbstractBorder {
    private Color numberColor;
         public LineNumberBorder() {
         public LineNumberBorder(Color lineNumberColor) {
              numberColor = lineNumberColor;
         * Paints the border for the specified component with the specified
         * position and size.
         * @param c the component for which this border is being painted
         * @param g the paint graphics
         * @param x the x position of the painted border
         * @param y the y position of the painted border
         * @param width the width of the painted border
         * @param height the height of the painted border
         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height){
              if (!(c instanceof SyntaxedEditor)) {
                   return;
              Insets insets = getBorderInsets(c);
              Color oldColor = g.getColor();
              if (numberColor == null) numberColor = c.getForeground();
              g.setColor(numberColor);
              g.translate(x, y);
              SyntaxedEditor ta = (SyntaxedEditor) c;
         // Mask the left margin area
              Graphics cg = g.create();
              cg.setClip(0, insets.top, insets.left, height - insets.top);
              Font f = ta.getFont();
              FontMetrics fm = cg.getFontMetrics(f);
              int lines = ta.getLineCount();
              for (int i = 0; i < lines; i++) {
                   try {
                        Rectangle r = ta.modelToView(ta.getLineStartOffset(i));
                        int lx = insets.left - fm.stringWidth("W" + (i+1));
                        int ly = r.y + fm.getLeading() + fm.getMaxAscent();
                        //draw the line number (as a string) at the coordinates provided
    //how can I tell whether ly is outside of the viewable area?
                        cg.drawString("" + (i+1), lx, ly);
                   } catch (BadLocationException ble) {
              cg.dispose();
              g.setColor(oldColor);
         * Returns the insets of the border.
         * @param c the component for which this border insets value applies
         public Insets getBorderInsets(Component c){
              if (!(c instanceof SyntaxedEditor)) {
                   return new Insets(0,0,0,0);
              FontMetrics fm = c.getFontMetrics(c.getFont());
              //int margin = fm.stringWidth("WWWW");
              int margin = fm.stringWidth( new String("W"+((SyntaxedEditor)c).getLineCount()) );
              return new Insets(0,margin,0,0);
         * Returns whether or not the border is opaque. If the border
         * is opaque, it is responsible for filling in it's own
         * background when painting.
         public boolean isBorderOpaque(){
              return false;
         public static void main(String args[]){
              JFrame jf = new JFrame();
              Container cp = jf.getContentPane();
              cp.setLayout(new BorderLayout());
              SyntaxedEditor ta = new SyntaxedEditor();
              //all we need to do is this...
              ta.setBorder( new LineNumberBorder(Color.red) );
              //ta.setLineWrap(true);
              cp.add(new JScrollPane(ta), BorderLayout.CENTER);
              jf.setSize(300, 400);
              jf.setVisible(true);
              jf.addWindowListener(new WindowAdapter() {
              public void windowActivated(WindowEvent e) {}
              public void windowClosed(WindowEvent e) {}
              public void windowClosing(WindowEvent e) {System.exit(0);}
              public void windowDeactivated(WindowEvent e) {}
              public void windowDeiconified(WindowEvent e) {}
              public void windowIconified(WindowEvent e) {}
              public void windowOpened(WindowEvent e) {}});
    } // LineNumberBorder

    The LineNumberBorder just extends AbstractBorder which extends Object, so there can't be any issues about mixing heavy weight and light weight components... can there?
    I'm stumped. The border is painting all the line numbers, as I would expect from the code, but the Scrollpane isn't hiding them. The numbers paint right on top of surrounding components until some action on my part causes those comps to explicitly repaint themselves.
    Any ideas? Anyone?

  • ScrollPane component smooth scrolling

    Hello. I just started working with AS 3.0 and I'm yet
    learning basics. I searched google and couldnt find the answer to
    my question; How to make scrolling on ScrollPane component smooth
    with AS 3.0? Please help.

    Hello. I just started working with AS 3.0 and I'm yet
    learning basics. I searched google and couldnt find the answer to
    my question; How to make scrolling on ScrollPane component smooth
    with AS 3.0? Please help.

Maybe you are looking for

  • DNS Setup/View external website internally

    Greetings all - trying to set up a Mac server from scratch for the first time. Been managing one for a while but didn't actually set it up myself. I have the beginnings of DNS setup all squared away, but am still looking to figure out how to properly

  • Got  system error while executing the workbook

    Hi All, While executing the workbook, I m getting the following error:=- Abort system error:RSDRC/ Function rsdrc_cube datget_disp rfc tas Abort system error:RSDRC/ Func RSRDC_MULTICUBE_DATA_GET_PARA ERROR IN RSDRC_

  • Do I need a dedicated hard drive?

    I have a 320GB Firewire Seagate HD with some important files on it, but I would like to use it as my Time Machine drive as well (plenty of space). Question is: will TM erase things on the drive when I first use it? Will it format the drive in some wa

  • Can't copy text in a preview-document opened in Safari.

    Since the last upgrade of safari (I think) I can't copy text in a preview document opened in Safari. Can I adjust anything in the preferences or is there any other solution to get the normal behaviour back?

  • Internet through computer connection

    Is there a way I can connect to the internet by pluging my iPhone into my Mac directly? I've tried and it doesn't seem to work. Is there a setting I need to put into place?