Position of scrollbar in a scrollpane

Hello ,
I am using a scrollpane and the default position of the scroll bars are like this :
<content><content><content><content><content>|
<content><content><content><content><content>|
<content><content><content><content><content>|
<content><content><content><content><content>|
<content><content><content><content><content>|
<horizontal scrollbar >< horizontal scrollbar>
where "|" stands for my vertical scrollbar.
is there any way to move the horizontal scrollbar up
such that the vertical scrollbar is the one touching the bottom of the scrollpane ? i.e something like this :
<content><content><content><content><content>|
<content><content><content><content><content>|
<content><content><content><content><content>|
<content><content><content><content><content>|
<content><content><content><content><content>|
<horizontal scrollbar><horizontal scrollbar> |
any idea is welcome, thanks.

Sounds like this is what you have And this is what you want
| |/\| | |/\|
| Content |||| | Content ||||
| Content | | | Content | |
| Content | | | Content | |
| Content | | | Content | |
| | | | |\/|
|----------------| | |----------------|--|
|<== >|\/| |<== >| |
You could tring to make two scrollpanes. Add one to the other and specifying that you wish no vertical scroller on one and on the other no horizontal.
----------------- -------------------V
| | | |/\|e
| Content | add this to | ||||r
| Content | ====> | | |t
| Content | | | |i
| Content | | | |c
| | | |\/|a
----------------- -------------------l
<=== >
Horizontal
Hopefully you'll end up with something like
| |/\|
| Content ||||
| Content | |
| Content | |
| Content | |
| | |
|----------------| |
|<== >|\/|
I don't know how complicated this next bit might be but it may be possible to tie in the vertical scroller so that you scroll in the inner scroll pane.
Hope thats of some use to you.

Similar Messages

  • How to set position of scrollbar

    Hi,
    I need to set a scrollbar at specific position depending on buttons a user would click. Does anyone has an idea on how to do this. Thanks
    Nessen

    Hi,
    sorry I did not express my question properly. I've got a JscrollPane that I want to make scroll to a specific position when a button is pressed. I'm initiallising Jscrollpane like this:
    JScrollPane scrollPane = new JScrollPane(disp,
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    is there a way to do this,
    thanks
    Nessen

  • I need to get the position of scrollBar in JScrollPane

    I have two JTables pleaced in JScrollPanes. User can drag a cell from the first table and drop it on the second. I catch selected row nr in the first tible when dragging starts (using rowAtPoint(e.getPoint())) and when user releases mouse I need to calculate the position on the second table.
    Everything works great but if scrollBar in the first table is scrolled down I have a position of pointWhereMouseIsReleased == pointOnScreen+positionOfScrollBar
    All I need to get is the position of the scroll bar. I tried to use getValue() and so on but it didn't work.
    Any sugestions?
    Thank you,
    Przemek

    ((JViewport)table.getParent()).getViewPosition()will give you the position of the upper-left-hand corner of the viewport, in your JTable's coordinate system. Is that what you need?

  • Scrollpane - no scrollbars when minimised

    Does anyone know what the cause of this problem is? When I minimise the screen I won't get any scrollbars when the contents within the scrollpane is larger than the scrollpane (and when no scrollbar is required in a miximised position). However if the contents is larger then the scrollpane in the maximised position then scrollbar will appear. My programs have some components witin a panel within a scrollpane within a tabbedpane.
    Thanks
    Peter Loo

    Maybe your JScrollPane should not have a setMinimumSize,
    and your scrolled JPanel should have a setMinimumSize.

  • Scrollbar knob colored in a scrollpane

    I would like to have the knob of the scrollbar in a scrollpane colored with a non gray color. All the tutorial examples come with a light blue color. But I don't know how to get it.
    I also have the same problem with the selected rows of a Jtable.
    Any ideas? Tanks

    .... I should add that this method should be called before you create the component and will effect all of these components created after this.
    eg
    public static void main(String[] args){
    UIManager.put("ScrollBar.thumb", new ColorUIResource(Color.blue));
    // create the scrollbar here
    For a complete explaination of what is going on checkout:
    www.spindoczine.com.sbe/files/uts2/chapter21html/Chapter21.htm

  • ScrollPane: Howto have vert. scrollbar on left side ?

    Is there a way to have the vertical scrollbar (on a scrollpane) on the left side (rather than on the right side) ?

    AFAIK only by using your own skin for ScrollPane (and probably TreeView, ListView and TableView).

  • Trapping the addition of ScrollBar on ScrollPane.

    Hi All,
    I have a Panel in which there is a JScrollPane(with JTextArea) and a button. On the click of button we add the components dynamically to the Panel. Now since the size of the Panel(inside a frame) will remain the same therefore adding components at run time will add ScrollBar to the ScrollPane(as it is reduced in size).
    So what i have to do is to trap the moment at which the scrollbar comes into picture. That is when i keep on adding some components dynamically at run time so at some time the scrollbar will be added to scrollPane. All i have to do is display a message at the moment when the ScrollBar is visible.
    I am stuck with this for almost a day....... Please help soon

    What you can do (it's pretty ugly and I haven't tested it) is this :
    - subclass JScrollPane
    - override the createVerticalScrollBar() and createHorizontalScrollBar()
    - in both overriden methods return a subclass of JScrollPane.ScrollBar instance in which you will have overriden the setVisible(boolean aFlag) method.
    - in the setVisible method, you may test the value of the flag.

  • ScrollPane from scratch

    Hello to you !
    I'd like to create my own scrollpane, i don't want to use swing or awt.ScrollPane. My problem are the following:
    1) How to find the size ( height ) of the thumb/bubble/knob whatever ?
    2) How to find the correct incrementation according the Panel being scrolled and my ScrollPane ?
    Here is my code:
    public void init(){
              setSize(500,500);
              setLayout(null);
              Panel p = new Panel();
              p.setLayout(null);
              p.setBounds(0,0,300,400);
              p.setBackground(Color.blue);
              Label a = new Label("top");
              a.setForeground(Color.white);
              a.setBounds(0,0,150,15);
              p.add(a);
              Label b = new Label("bottom");
              b.setBounds(0,p.getSize().height-15,150,15);
              b.setForeground(Color.white);
              p.add(b);
              myScrollBars ms = new myScrollBars(p);
              ms.setBounds(50,50,300,200);
              add(ms);
    Here we have a Panel i'd like to scroll (300*400) and my ScrollBars (300*200)
    public myScrollBars(Panel p){ //extends Panel
         this.p = p;
         setLayout(null);
         setBackground(Color.lightGray);
         vscroller = new VScroller(this);
         add(vscroller);
         add(p);
    Then i set the bounds of my ScrollBars (ScrollPane)
    public void setBounds(int x,int y,int w,int h){
         super.setBounds(x,y,w,h);
         vscroller.setBounds(w-16,0,16,h);
         float d      = h;
         float d2      = p.getBounds().height;
         float d3      = d/d2;
         float d4      = d3*100;
         int d5     = Math.round(d4);
         vscroller.calculate(Math.round(d),Math.round(d2),d5);
    public VScroller(myScrollBars mys) { //This is my Vertical ScrollBar
         this.mys = mys;     
         setLayout(null);
         aUP = new Canvas(){
              public void paint(Graphics g){
         g.setColor(Color.white);
         g.draw3DRect(0,0,13,13,raised);
         int[] x = {3,7,11};
         int[] y = {10,4,10};
                   g.drawPolyline(x,y,3);
         aUP.setBackground(Color.gray);
         aUP.addMouseListener(this);
         aUP.setBounds(0,0,16,16);
         //add(aUP);
         aDOWN = new Canvas(){
                   public void paint(Graphics g){
                        g.setColor(Color.white);
                        g.draw3DRect(0,0,13,13,raised);
                        int[] x = {3,7,11};
         int[] y = {4,10,4};
              g.drawPolyline(x,y,3);
         aDOWN.setBackground(Color.gray);
         aDOWN.addMouseListener(this);
         add(aDOWN);
         bubble = new Canvas(){ // This is the thumb / knob
                   public void paint(Graphics g){
                        g.setColor(Color.white);
                        //g.draw3DRect(0,0,13,99,raised);
         bubble.setBackground(Color.gray);
         bubble.addMouseListener(this);
         bubble.addMouseMotionListener(this);
         add(bubble);
    Now here is the real problem !!!!
    I need to calculate the correct size (height) of the thum (which is the proportion between the panel i want to scroll and my scrollpane) and the correct incrementation, in order to always reach the "bottom" of the panel to scroll, and the bubble must too be at the bottom...do you get the complexity ???
    public void calculate(int scroll,int pP, int thumb){
         int diffY      = (scroll)-(thumb);//scrollable area
         System.out.println("DIFF = "+(pP-scroll));
         System.out.println("THUMB = "+thumb);
         System.out.println("DIFFY = "+diffY);
         float diff      = (pP-scroll);
         float f      = diff/diffY;
         increment      = Math.round(f);
         getBubble().setBounds(2, 0, 12,(thumb/increment));
    I hope that i'm clear enough
    Thanks if you can help !!!!!
    Guido

    try this:
    Ls length of scrollbar
    Lts length of thingy on scrollbar
    Ps position of scrollbar messured at the top edge
    Ld Length of the document/object in the scrollpane
    Lwd Length of the window in the scrollpane
    Pd Position of the window in the document, messured from the top edge
    first calculate the apropriate size of the thingy using the this equation
    Lts/Ls = Lwd/ld
    with the border condition that Lts should never be smaller then a certain minimum, to prevent thingies of the size less then a pixel
    Now calculate the position:
    (Ls-Lts)/Ps = (Ld -Lwd)/Pd
    After you fixed various rounding and +/-1 problems you are likely to encounter this should work.
    regards
    Spieler

  • I cant use ScrollPane in JList

    JList list=new JList(kaynak);
    list.setBounds(0,0,40,40);
    JScrollPane sc=new JScrollPane(list);
    add(list);
    add(sc);
    setVisible(true);
    why I do not have scrollBars arround my jlist? what is the problem?

    JList list=new JList(kaynak);
    list.setBounds(0,0,40,40);
    ScrollPane sc=new JScrollPane(list);
    add(list);
    add(sc);
    setVisible(true);
    why I do not have scrollBars arround my jlist? what
    is the problem?You've added the list to the scroll pane, but then you add the list to the frame. And then you add the scrollpane to the frame.
    This approach contains two flaws:
    A. You can't add a component to two different parents. When you try to do so, the component is removed from the original parent and added to the new parent. So, when your code says
    add(list);the list is removed from the scrollpane and added to the frame.
    B. You can't add two different components to the same container without indicating where to put them. Assuming your container has a default BorderLayout, your code adds the list at the CENTER position, and then adds the scrollpane at the CENTER position. As a result, your list is removed from the container and the scrollpane is added. but since the first flaw in your code removed the list from the scrollpane, nothing appears. The scrollpane is there, but it has nothing in it so the frame appears empty.
    Remove the line:
    add(list);and things should work.
    Jim S.

  • How to setup and position resizable Scroll Bars in Java ?

    I seem to be asking a trivial question -
    I having MFC code below, how to convert it to Java ?
    For a given bigger image_dims and smaller view_dims -
    MFC code below sets-up and positions the ScrollBars.
    What is the corresponding class and member functions in Java ?
    Thanks A LOT for any help !
    Roman Kazinnik
    ====
    sc_info.fMask = SIF_DISABLENOSCROLL | SIF_ALL;
    sc_info.nMin = 0;
    sc_info.nMax = image_dims.size.y-1;
    sc_info.nPage = view_dims.size.y;
    sc_info.nPos = view_dims.pos.y - image_dims.pos.y;
    child->SetScrollInfo(SB_VERT,&sc_info);
    kdu_coords step = view_dims.size;
    step.x = (step.x >> 4) + 1;
    step.y = (step.y >> 4) + 1;
    kdu_coords page = view_dims.size - step;
    child->set_scroll_metrics(step,page,image_dims.size-view_dims.size);
    ====

    hi lev,
    check this document for jco pools
    http://www.winfobase.de/lehre/lv_materialien.nsf/intern01/FB09D79A41930E34C125709F0046180C/$FILE/Tips&Tricks_JCo_Programming.pdf
    ravindra

  • ScrollPane doesn't display its content

    I created a scrollpane in as3 and set its source to another object, which contains several rows of icons.
    The scrollbar in the scrollpane is getting the right length, which means the object was loaded as expected, but the contant is not showing correctly.
    I created a Thumbnail class for this file to load and make each individual thumbnail.
    Here is my code, the red text is where each thumbnail is loaded:
    import fl.containers.UILoader;
    import caurina.transitions.*;
    import flash.events.Event;
    import fl.containers.ScrollPane;
    var urlRequest:URLRequest = new URLRequest("pics.xml");
    var urlLoader:URLLoader = new URLLoader();
    var myXML:XML = new XML();
    var xmlList:XMLList;
    myXML.ignoreWhitespace = true;
    urlLoader.addEventListener(Event.COMPLETE,fileLoaded);
    urlLoader.load(urlRequest);
    var arrayURL:Array = new Array();
    var arrayName:Array = new Array();
    var holderArray:Array = new Array();
    var nrColumns:uint = 3;
    var sprite:Sprite = new Sprite();
    addChild(sprite);
    var thumb:Thumbnail;
    var thumbsHolder:Sprite = new Sprite();
    sprite.addChild(thumbsHolder);
    var loaderHolder:Sprite = new Sprite();
    loaderHolder.graphics.beginFill(0x666666,1);
    loaderHolder.graphics.drawRoundRect(0,0,450,340, 20,20);
    loaderHolder.graphics.endFill();
    loaderHolder.x = 280;
    loaderHolder.y = 240;
    sprite.addChild(loaderHolder);
    var photoLoader:UILoader = new UILoader();
    photoLoader.width = 450;
    photoLoader.height = 340;
    photoLoader.y = 5;
    photoLoader.x = 5;
    photoLoader.buttonMode = true;
    photoLoader.addEventListener(MouseEvent.CLICK,onClickBack);
    loaderHolder.addChild(photoLoader);
    var scrollPane:ScrollPane=new ScrollPane();
    var skin:MovieClip = new MovieClip();
    scrollPane.x = 805;
    scrollPane.y = 405;
    scrollPane.width = 215;
    scrollPane.height = 280;
    scrollPane.setStyle( "skin", skin );
    scrollPane.setStyle( "upSkin", skin );
    scrollPane.source = thumbsHolder;
    sprite.addChild(scrollPane);
    function fileLoaded(event:Event):void
    myXML = XML(event.target.data);
    xmlList = myXML.children();
    for (var i:int=0; i<xmlList.length(); i++)
      var picURL:String = xmlList[i].url;
      var picName:String = xmlList[i].big_url;
      arrayURL.push(picURL);
      arrayName.push(picName);
      holderArray[i] = new Thumbnail(arrayURL[i],i,arrayName[i]);
      holderArray[i].addEventListener(MouseEvent.CLICK,onClick);
      holderArray[i].name = arrayName[i];
      holderArray[i].buttonMode = true;
      if (i<nrColumns)
       holderArray[i].y = 440;
       holderArray[i].x = i * 65 + 840;
      else
       holderArray[i].y = holderArray[i - nrColumns].y + 65;
       holderArray[i].x = holderArray[i - nrColumns].x;
      thumbsHolder.addChild(holderArray[i]);
      scrollPane.update();
    function onClick(event:MouseEvent):void
    photoLoader.alpha = 0.1;
    photoLoader.source = event.currentTarget.name;
    photoLoader.addEventListener(Event.COMPLETE, fadeOut);
    function fadeOut(event:Event):void
      Tweener.addTween(photoLoader, {alpha:1, time:0.5, transition:"linear"});
    function onClickBack(event:MouseEvent):void
      Tweener.addTween(loaderHolder, {alpha:.5, time:2, transition:"linear"});

    Bold is about the only text editing feature that works in the current editor panel.  The rest were disabled due to spam-related abuse (addng white text, etc)
    I cannot really follow what is going into where and where it is being put (just too lazy to track it down at this time of night), but it sounds like it might be possible that your content is being planted at a location that it is not visible in the scrollpane panel.  The scrollpane is only 215 pixels wide but you have something called a loaderHolder that is being placed at x = 280.  And then elsewhere you have holderArray[i].x = i * 65 + 840;, which is placing it well beyond the 215 width.

  • Resizing ScrollPane and Dimension dynamically

    I am currently making a scrollbar program using ScrollPane and Dimension. I have to use those classes.
    When I click "ok" button, that calls dc.enlarge(500,800) method. But it doesn't work.
    When it is clicked, Dimension object should be changed and the panel has to show Horizotal
    and Vertical scrollbar according to the width and height parameters.
    Of course, the size will be calculated by the String contents object's rows and width. But it does not work.
    How to resize the Dimension and How to display the Horizontal, Vertical scrollbar accoring to dc.enlarge's parameters?
    Plz... help me...
    -------------- ScrollerTest.java -----------------------------------------------
    import java.awt.*;
    import java.applet.Applet;
    public class ScrollerTest extends Applet {
       public Scroller sc = null;
        public void init() {
            sc = new Scroller(700,250);
            sc.setVisible(true);
         add(sc);         
    }-------------- Scroller.java -----------------------------------------------
    import java.awt.*;
    import java.awt.Window;
    import java.applet.Applet;
    import java.awt.event.*;
    public class Scroller extends Panel implements  ActionListener {
        private Button btOk;   
        private int width = 0;
        private int height = 0;   
        private DrawCanvas dc;   
        public Scroller(int width, int height){   
            this.width = width;
            this.height = height;   
            dc = new DrawCanvas(width, height);
            setNewsContents();                           
        private void setNewsContents() {
            setLayout(new BorderLayout());
            ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);       
            scroller.add(dc);
            Adjustable vadjust = scroller.getVAdjustable();
            Adjustable hadjust = scroller.getHAdjustable();
            hadjust.setUnitIncrement(10);
            vadjust.setUnitIncrement(10);
            scroller.setSize(615     , 272);
            btOk = new Button("ok");
            btOk.addActionListener(this);
            add("Center", scroller);
            add("South", btOk);       
        public void actionPerformed(ActionEvent event) {
            if(event.getSource()==btOk) {
                dc.enlarge(500,800);
                dc.validate();
    }    -------------- DrawCanvas.java -----------------------------------------------
    import java.awt.*;
    class DrawCanvas extends Component {
        private int width = 0;
        private int height = 0;
        private Dimension d;
        public DrawCanvas(int width, int height) {
            this.width = width;
            this.height = height;
       Dimension theSize = new Dimension(300, 200);   
       public Dimension getPreferredSize() {
            return new Dimension(width,height);               
       public void enlarge(int width, int height) {       
            theSize.width =  width;
            theSize.height = height;
            setSize(theSize);       
        public void update(Graphics g) {
            paint(g);
        public void paint(Graphics g) {       
            Rectangle r = getBounds();       
            String contents[] = {
            "addition to its usual stable of Clydesdale horses, the company will also enlist help this year ",
            "from racing star Dale Earnhardt Jr., some beer-thieving crabs and a scary hitchhiker.",       
            "The Super Bowl represents an enormous commitment for Budweiser. Bob Lachky, chief creative" ,
            "officer of Anheuser-Busch, said the St. Louis-based brewer has been advertising on the game since 1976 and has been the exclusive alcoholic beverage sponsor since 1989",
            "since 1976 and has been the exclusive alcoholic beverage sponsor since 1989, an arrangement that runs through 2012.",
            "It's important to us because it kicks off our selling season, it's the best platform",
            "possible to launch new ideas or to sustain existing campaigns, and it's absolutely the most efficient way to reach the most  it's absolutely the most efficient way to reach the most",
            "adult consumers in one sitting,",
            "Despite the rise of cable, the Internet other media to compete with broadcast television iewers and enticing a huge array of marketers ",
            ", the Super Bowl remains the most-viewed media event all year, drawing in some 90 million ",
            "viewers and enticing a huge array of marketers to pony up the big bucks for an ad",
            ", the price of which is running as high as $2.6 million for this year's broadcast",
            "on CBS Corp.'s CBS network, up slightly from about a top price of about $2.5 million last year.",
            "Comedian Carlos Mencia, of the Comedy Central show  gets ",
            "a big break with a spot set in a classroom. Lachky predicts that Mencia will get an enormous boost Lachky predicts that Mencia will get an enormous boost ",
            "following the appearance, which similarly did wonders for Cedric the Entertainer.",
            "And what would Budweiser Super Bowl ads be without some animated critters? This year, a ga",
            "ng of mischievous red crabs turn up on a beach to carry off a cooler full of beers. As in past years, Bud is keeping many ",
            g.setColor(new Color(226,250,255));
            g.fillRect(0, 0, r.width, r.height);
            g.setColor(new Color(233,231,224));            
            int line = 35;
            int line_1 = 39;
            for (int i = 0; i < contents.length; i++) {       
                 g.setColor(Color.BLACK);
                 g.drawString(contents, 5,line);
         g.setColor(new Color(233,231,224));
         g.drawLine(0,line_1,605,line_1);
         line += 20;
         line_1 += 20;

    I am currently making a scrollbar program using ScrollPane and Dimension. I have to use those classes.
    When I click "ok" button, that calls dc.enlarge(500,800) method. But it doesn't work.
    When it is clicked, Dimension object should be changed and the panel has to show Horizotal
    and Vertical scrollbar according to the width and height parameters.
    Of course, the size will be calculated by the String contents object's rows and width. But it does not work.
    How to resize the Dimension and How to display the Horizontal, Vertical scrollbar accoring to dc.enlarge's parameters?
    Plz... help me...
    -------------- ScrollerTest.java -----------------------------------------------
    import java.awt.*;
    import java.applet.Applet;
    public class ScrollerTest extends Applet {
       public Scroller sc = null;
        public void init() {
            sc = new Scroller(700,250);
            sc.setVisible(true);
         add(sc);         
    }-------------- Scroller.java -----------------------------------------------
    import java.awt.*;
    import java.awt.Window;
    import java.applet.Applet;
    import java.awt.event.*;
    public class Scroller extends Panel implements  ActionListener {
        private Button btOk;   
        private int width = 0;
        private int height = 0;   
        private DrawCanvas dc;   
        public Scroller(int width, int height){   
            this.width = width;
            this.height = height;   
            dc = new DrawCanvas(width, height);
            setNewsContents();                           
        private void setNewsContents() {
            setLayout(new BorderLayout());
            ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);       
            scroller.add(dc);
            Adjustable vadjust = scroller.getVAdjustable();
            Adjustable hadjust = scroller.getHAdjustable();
            hadjust.setUnitIncrement(10);
            vadjust.setUnitIncrement(10);
            scroller.setSize(615     , 272);
            btOk = new Button("ok");
            btOk.addActionListener(this);
            add("Center", scroller);
            add("South", btOk);       
        public void actionPerformed(ActionEvent event) {
            if(event.getSource()==btOk) {
                dc.enlarge(500,800);
                dc.validate();
    }    -------------- DrawCanvas.java -----------------------------------------------
    import java.awt.*;
    class DrawCanvas extends Component {
        private int width = 0;
        private int height = 0;
        private Dimension d;
        public DrawCanvas(int width, int height) {
            this.width = width;
            this.height = height;
       Dimension theSize = new Dimension(300, 200);   
       public Dimension getPreferredSize() {
            return new Dimension(width,height);               
       public void enlarge(int width, int height) {       
            theSize.width =  width;
            theSize.height = height;
            setSize(theSize);       
        public void update(Graphics g) {
            paint(g);
        public void paint(Graphics g) {       
            Rectangle r = getBounds();       
            String contents[] = {
            "addition to its usual stable of Clydesdale horses, the company will also enlist help this year ",
            "from racing star Dale Earnhardt Jr., some beer-thieving crabs and a scary hitchhiker.",       
            "The Super Bowl represents an enormous commitment for Budweiser. Bob Lachky, chief creative" ,
            "officer of Anheuser-Busch, said the St. Louis-based brewer has been advertising on the game since 1976 and has been the exclusive alcoholic beverage sponsor since 1989",
            "since 1976 and has been the exclusive alcoholic beverage sponsor since 1989, an arrangement that runs through 2012.",
            "It's important to us because it kicks off our selling season, it's the best platform",
            "possible to launch new ideas or to sustain existing campaigns, and it's absolutely the most efficient way to reach the most  it's absolutely the most efficient way to reach the most",
            "adult consumers in one sitting,",
            "Despite the rise of cable, the Internet other media to compete with broadcast television iewers and enticing a huge array of marketers ",
            ", the Super Bowl remains the most-viewed media event all year, drawing in some 90 million ",
            "viewers and enticing a huge array of marketers to pony up the big bucks for an ad",
            ", the price of which is running as high as $2.6 million for this year's broadcast",
            "on CBS Corp.'s CBS network, up slightly from about a top price of about $2.5 million last year.",
            "Comedian Carlos Mencia, of the Comedy Central show  gets ",
            "a big break with a spot set in a classroom. Lachky predicts that Mencia will get an enormous boost Lachky predicts that Mencia will get an enormous boost ",
            "following the appearance, which similarly did wonders for Cedric the Entertainer.",
            "And what would Budweiser Super Bowl ads be without some animated critters? This year, a ga",
            "ng of mischievous red crabs turn up on a beach to carry off a cooler full of beers. As in past years, Bud is keeping many ",
            g.setColor(new Color(226,250,255));
            g.fillRect(0, 0, r.width, r.height);
            g.setColor(new Color(233,231,224));            
            int line = 35;
            int line_1 = 39;
            for (int i = 0; i < contents.length; i++) {       
                 g.setColor(Color.BLACK);
                 g.drawString(contents, 5,line);
         g.setColor(new Color(233,231,224));
         g.drawLine(0,line_1,605,line_1);
         line += 20;
         line_1 += 20;

  • Resizing ScrollPane and Dimension

    I am currently making a scrollbar program using ScrollPane and Dimension. I have to use those classes.
    When I click "ok" button, that calls dc.enlarge(500,800) method. But it doesn't work.
    When it is clicked, Dimension object should be changed and the panel has to show Horizotal
    and Vertical scrollbar according to the width and height parameters.
    Of course, the size will be calculated by the String contents object's rows and width. But it does not work.
    How to resize the Dimension and How to display the Horizontal, Vertical scrollbar accoring to dc.enlarge's parameters?
    Plz... help me...
    -------------- ScrollerTest.java -----------------------------------------------
    import java.awt.*;
    import java.applet.Applet;
    public class ScrollerTest extends Applet {
       public Scroller sc = null;
        public void init() {
            sc = new Scroller(700,250);
            sc.setVisible(true);
         add(sc);         
    }-------------- Scroller.java -----------------------------------------------
    import java.awt.*;
    import java.awt.Window;
    import java.applet.Applet;
    import java.awt.event.*;
    public class Scroller extends Panel implements  ActionListener {
        private Button btOk;   
        private int width = 0;
        private int height = 0;   
        private DrawCanvas dc;   
        public Scroller(int width, int height){   
            this.width = width;
            this.height = height;   
            dc = new DrawCanvas(width, height);
            setNewsContents();                           
        private void setNewsContents() {
            setLayout(new BorderLayout());
            ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);       
            scroller.add(dc);
            Adjustable vadjust = scroller.getVAdjustable();
            Adjustable hadjust = scroller.getHAdjustable();
            hadjust.setUnitIncrement(10);
            vadjust.setUnitIncrement(10);
            scroller.setSize(615     , 272);
            btOk = new Button("ok");
            btOk.addActionListener(this);
            add("Center", scroller);
            add("South", btOk);       
        public void actionPerformed(ActionEvent event) {
            if(event.getSource()==btOk) {
                dc.enlarge(500,800);
                dc.validate();
    }    -------------- DrawCanvas.java -----------------------------------------------
    import java.awt.*;
    class DrawCanvas extends Component {
        private int width = 0;
        private int height = 0;
        private Dimension d;
        public DrawCanvas(int width, int height) {
            this.width = width;
            this.height = height;
       Dimension theSize = new Dimension(300, 200);   
       public Dimension getPreferredSize() {
            return new Dimension(width,height);               
       public void enlarge(int width, int height) {       
            theSize.width =  width;
            theSize.height = height;
            setSize(theSize);       
        public void update(Graphics g) {
            paint(g);
        public void paint(Graphics g) {       
            Rectangle r = getBounds();       
            String contents[] = {
            "addition to its usual stable of Clydesdale horses, the company will also enlist help this year ",
            "from racing star Dale Earnhardt Jr., some beer-thieving crabs and a scary hitchhiker.",       
            "The Super Bowl represents an enormous commitment for Budweiser. Bob Lachky, chief creative" ,
            "officer of Anheuser-Busch, said the St. Louis-based brewer has been advertising on the game since 1976 and has been the exclusive alcoholic beverage sponsor since 1989",
            "since 1976 and has been the exclusive alcoholic beverage sponsor since 1989, an arrangement that runs through 2012.",
            "It's important to us because it kicks off our selling season, it's the best platform",
            "possible to launch new ideas or to sustain existing campaigns, and it's absolutely the most efficient way to reach the most  it's absolutely the most efficient way to reach the most",
            "adult consumers in one sitting,",
            "Despite the rise of cable, the Internet other media to compete with broadcast television iewers and enticing a huge array of marketers ",
            ", the Super Bowl remains the most-viewed media event all year, drawing in some 90 million ",
            "viewers and enticing a huge array of marketers to pony up the big bucks for an ad",
            ", the price of which is running as high as $2.6 million for this year's broadcast",
            "on CBS Corp.'s CBS network, up slightly from about a top price of about $2.5 million last year.",
            "Comedian Carlos Mencia, of the Comedy Central show  gets ",
            "a big break with a spot set in a classroom. Lachky predicts that Mencia will get an enormous boost Lachky predicts that Mencia will get an enormous boost ",
            "following the appearance, which similarly did wonders for Cedric the Entertainer.",
            "And what would Budweiser Super Bowl ads be without some animated critters? This year, a ga",
            "ng of mischievous red crabs turn up on a beach to carry off a cooler full of beers. As in past years, Bud is keeping many ",
            g.setColor(new Color(226,250,255));
            g.fillRect(0, 0, r.width, r.height);
            g.setColor(new Color(233,231,224));            
            int line = 35;
            int line_1 = 39;
            for (int i = 0; i < contents.length; i++) {       
                 g.setColor(Color.BLACK);
                 g.drawString(contents, 5,line);
         g.setColor(new Color(233,231,224));
         g.drawLine(0,line_1,605,line_1);
         line += 20;
         line_1 += 20;

    The class names have been changed so you can run this as-is without name-clashing.
    //  <applet code="ST" width="720" height="300"></applet>
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    public class ST extends Applet {
        public ScrollerRx sc;
        public void init() {
            sc = new ScrollerRx(700,250);
            add(sc);
    class ScrollerRx extends Panel implements ActionListener {
        private Button btOk;
        private DrawCanvasRx dc;
        public ScrollerRx(int width, int height) {
            dc = new DrawCanvasRx(width, height);
            setNewsContents();
        private void setNewsContents() {
            setLayout(new BorderLayout());
            ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
            scroller.add(dc);
            Adjustable vadjust = scroller.getVAdjustable();
            Adjustable hadjust = scroller.getHAdjustable();
            hadjust.setUnitIncrement(10);
            vadjust.setUnitIncrement(10);
            scroller.setSize(615, 272);
            btOk = new Button("ok");
            btOk.addActionListener(this);
            add("Center", scroller);
            add("South", btOk);
        public void actionPerformed(ActionEvent event) {
            if(event.getSource()==btOk) {
                dc.enlarge(500,800);
                // validate is a Container method.
                validate();
    class DrawCanvasRx extends Component {
        Dimension theSize = new Dimension(300, 200);
        String[] contents = {
            "addition to its usual stable of Clydesdale horses, the company will " +
            "also enlist help this year ",
            "from racing star Dale Earnhardt Jr., some beer-thieving crabs and a " +
            "scary hitchhiker.",       
            "The Super Bowl represents an enormous commitment for Budweiser. Bob " +
            "Lachky, chief creative" ,
            "officer of Anheuser-Busch, said the St. Louis-based brewer has been " +
            "advertising on the game since 1976 and has been the exclusive alcoholic " +
            "beverage sponsor since 1989",
            "since 1976 and has been the exclusive alcoholic beverage sponsor since " +
            "1989, an arrangement that runs through 2012.",
            "It's important to us because it kicks off our selling season, it's the " +
            "best platform",
            "possible to launch new ideas or to sustain existing campaigns, and it's " +
            "absolutely the most efficient way to reach the most  it's absolutely " +
            "the most efficient way to reach the most",
            "adult consumers in one sitting,",
            "Despite the rise of cable, the Internet other media to compete with " +
            "broadcast television iewers and enticing a huge array of marketers ",
            ", the Super Bowl remains the most-viewed media event all year, drawing " +
            "in some 90 million ",
            "viewers and enticing a huge array of marketers to pony up the big bucks " +
            "for an ad",
            ", the price of which is running as high as $2.6 million for this year's " +
            "broadcast",
            "on CBS Corp.'s CBS network, up slightly from about a top price of about " +
            "$2.5 million last year.",
            "Comedian Carlos Mencia, of the Comedy Central show  gets ",
            "a big break with a spot set in a classroom. Lachky predicts that Mencia " +
            "will get an enormous boost Lachky predicts that Mencia will get an " +
            "enormous boost ",
            "following the appearance, which similarly did wonders for Cedric the " +
            "Entertainer.",
            "And what would Budweiser Super Bowl ads be without some animated " +
            "critters? This year, a ga",
            "ng of mischievous red crabs turn up on a beach to carry off a cooler " +
            "full of beers. As in past years, Bud is keeping many ",
        public DrawCanvasRx(int width, int height) {
            theSize.setSize(width, height);
        public Dimension getPreferredSize() {
            System.out.printf("theSize = [%d, %d]%n", theSize.width, theSize.height);
            return theSize;
        public void enlarge(int width, int height) {
            theSize.width  = width;
            theSize.height = height;
            // Mark this component as needing a new layout.
            invalidate();
        public void update(Graphics g) {
            paint(g);
        public void paint(Graphics g) {
            Rectangle r = getBounds();
            g.setColor(new Color(226,250,255));
            g.fillRect(0, 0, r.width, r.height);
            g.setColor(new Color(233,231,224));
            int line = 35;
            int line_1 = 39;
            for (int i = 0; i < contents.length; i++) {
                g.setColor(Color.BLACK);
                 g.drawString(contents, 5, line);
         g.setColor(new Color(233,231,224));
         g.drawLine(0, line_1, 605, line_1);
         line += 20;
         line_1 += 20;

  • JTree - Position & Size

    I would like to display a JTree within a JScrollPane in JFrame.
    My problem is: I can't set the position and size of the scrollPane.
         public void SimpleTree() {
             WindowUtilities.setNativeLookAndFeel();
             addWindowListener(new ExitListener());
             Container content = getContentPane();
             DefaultMutableTreeNode root = readXMLFile();     
             JTree jtree = new JTree(root);
             jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
             JScrollPane scrollPane  = new JScrollPane(jtree);
             scrollPane.setViewportView(jtree);
               // ? ? ? what do I need in here       
             content.add(scrollPane);
             setVisible(true);
           } I tried a lot, bot It does not working :(
    Aykut

    Hi Aykut,
    The usual way to control the way components appear is to use a LayoutManager, which will allow you to dictate the overall layout for your content Container.
    Alternatively, if you want to place the JScrollPane at a specific place and a specific size, you can set the LayoutManager to be null, then use scrollPane.setBounds(...) to prescribe exactly where it will sit.
    The problem with the second choice (which appears at first glance to meet your requirements) is that different operating systems, with different native look-and-feels (as you're using) may vary in the exact size of components, borders, etc. and so may look better on one system than on others.
    For this reason, I'd take the time to look at the alternative LayoutManagers (you may find that the relatively simple BorderLayout or BoxLayout meets your needs), the added advantage being automatic resizing of your scrollPane when the main window is resized.
    I hope this is a helpful start though.
    Chris.

  • 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

Maybe you are looking for

  • Need help in creating a dropdown box inside a table control

    Hi, I need to display a calender upon click event of a dropdown box placed inside my table control. Can any body help me out. Regards, Srinivas

  • Converting UTF-16 to UTF-8

    Hi all, I have XML data in UTF-16 format in 'xml_result' using the below command. I need the data in UTF-8 format to download. How should i convert it? *CALL TRANSFORMATION id     SOURCE   H_EXP  = IGR     RESULT XML xml_result. Thanks

  • OAS 10g report and form service

    hi, i want to install OAS 10 for using form and report what should i do? ( os = linux oel4.7) plz help me

  • White Spot on LCD

    Product Name: HP 450 Notebook PC Serial Number:  5CG22610SF Windows 7 32bit White Spot on LCD...

  • Keyboard simulation in Java

    Hello How can I simulate a keystroke like Alt+Shift through java code? Thanks, Tomer