Scrollbars and awt.List

Hello,
I'm a first year student form the Netherlands in software design. And as of this semester I'm getting Java (finally a new language to learn!). Everything has gone very smoothly, I was hoping of more of a challenge trying to learn it, but it goes very easily (maybe I shouldn't have programmed in C++ for 3 years :P).
Though now I'm having a slight problem with my code. v _ v '
My project has to be competly in awt widget's, and I thought I'd do something more than required (it would seem that my teachers expect me to ^ _ ^).
In this list I'm required to use a fixed width font to "simulate" 2 panels (almost similar to the TableList in Swing) with a pipe ( | ) character as a line. It means that I need to cut off words that cross the boundry.
The above (and the rest of the assignment) works perfectly (and I've done the actual required part in less than 30 minutes), but now I've come to want to add tool tips to all the elements.
I've made a tooltip class (it works btw), but I need to get the item in the list my mouse is hovering over.
I believe a row is 20 pixels high (or something like that), so I divide the y value (of the local mouse position) by 20 and use the integer part as the index.
And here comes the problem.
When the list scrolls then the method I described above won't work anymore.
I think that my method is (atleast) similar as to what other programs do, save that it adds the scroll info as well.
Now here's my real problem. I can't (or don't know how) to get the scrollbar info from the list. I know there's a handy function is Swing, but I'm only allowed to use awt.
I've also read that the scrollbars are part of the peer's (native to the OS) so I can't access them.
So my true question is, what (if any) event should I listen to, to get scroll movements (not mouse wheel scrolling)?
And if there isn't any way to listen to the events, then do you have any idea how to tackle this problem?
Thank you for your time,
MLeoDaalder

Showing me your misbehaving output is not helpful.
I have successfully implemented what you are attempting, using Swing which I understand you cannot use but it should work the same way using AWT.
My main class extends JFrame (you would extend Frame) and implements MouseMotionListener. The mouseMoved(MouseEvent evt) method in the main class updates the tool tip, based on the evt.getX() and evt.getY().
I have a class (call it LCanvas) that extends JPanel (you would extend Panel) . The class adds a MouseMotionListener and has a paint(Graphics g) method that records the borders of each line that gets painted by g.drawString(String s, int x, int y). (Some of the painted lines may be outside of the displayed area.)
When I construct LCanvas, I pass it the JFrame (you would use Frame) of the main class. So my contructor looks like:
public LCanvas(JFrame f) {
addMouseMotionListener((MouseMotionListener) f);
Back in main(String [ ] args), I set up my scrollable window as:
MainClass f = new MainClass();
LCanvas lc = new LCanvas(f);
JScrollPane sp = new JScrollPane(lc);
content_pane.add(sp);
I don't know how you are trying to implement this but you should be able to compare it to my implementation that works and, since you are such a clever guy, figure out what's going wrong.

Similar Messages

  • Removing scrollbar from AWT List

    Hi,
    I have an instance of List on my screen. I noticed when I have more than one item on the list, it shows automatically a vertical and horizontal scrollbars.
    I have to disable scrollbars, but cannot find out if it is possible with AWT List or should I opt for a different Component than List.
    Could anyone give me a hand?
    Thank you,
    Caren

    List is what you want. Use this constructor...List(int, boolean). First argument is number of items to display in the list, second is if List is mulitle selection list. So for a normal list with 5 items do this:
    List myList = new List5, false);
    This should stop a scrollbar being put in (unless you add more than 5 items). If this doesn't work it's proably your layout manager set up.
    Hope this helps

  • To disable the horizontal scrollbar and to create a next button to navigate

    To disable the horizontal scrollbar and to create a next button to navigate through the records. At present I create a JSF page and drag and drop my table view and then using the Tuning property I have limited the number of records to be shown. But I need to add a button and then code it to display the next few records. Can someone kindly suggest a suitable mechanism to get this accomplished.
    Edited by: 888970 on Oct 2, 2011 10:15 PM

    Hi Erp,
    At present these are the entries that I have in my JSPX page.
    I have a Table, Iterator and a Input List of Values. As per the scenario, I want a few rows to appear on the table for which I wanted to disable the horizontal scroll bar and then once I click on the list of values it must prompt me with the remaining page numbers.
    Earlier there are about 150 records in the table. I want to show them as 15 per page.
    For which I have added the Iterator and a LOV component code in my JSPX page.
    <af:iterator id="i1"
    value="#{bindings.NsEventDetailsView1.collectionModel}"
    var="row"
    binding="#{pageFlowScope.testPageBean.myIterator}"/>
    <af:inputListOfValues label="Label 1"
    popupTitle="Search and Result Dialog" id="ilov1"/>
    Then I created the bean class as per the example.
    Below is the bean class:
    import javax.faces.event.ValueChangeEvent;
    import oracle.adf.view.rich.context.AdfFacesContext;
    import org.apache.myfaces.trinidad.component.UIXIterator;
    import org.apache.myfaces.trinidad.event.AttributeChangeEvent;
    public class TestPagebean {
    public TestPagebean() {
    public void i1ov1_valueChangeListener(ValueChangeEvent valueChangeEvent) {
    // Add event code here...
    private UIXIterator myiter;
    public void setI1(UIXIterator myiter) {
    this.myiter=myiter;
    public UIXIterator getmyiter() {
    this.myiter=myiter;
    public UIXIterator setmyiter() {
    return myiter;
    UIXIterator valueIterator = getmyiter();
    if (!valueChangeEvent.getNewValue().equals(valueChangeEvent.getOldValue())) {
    int newPage =
    Integer.parseInt(valueChangeEvent.getNewValue().toString());
    int pageStart = (newPage) * valueIterator.getRows();
    valueIterator.setFirst(pageStart);
    AdfFacesContext.getCurrentInstance().addPartialTarget(valueIterator);
    But i am getting errors in the bean class.
    1. Block expecting }
    2. public UIXIterator getmyiter() {
    this.myiter=myiter;
    Return Statement missing
    3. Block expecting {
    4. Type or variable 'valueChangeEvent' not found
    5. Method 'getNewValue' not found
    6. Method 'getOldValue' not found
    7. Method 'toString' not found
    Can you suggest a possible solution?

  • Help Needed With Scrollbar and Content

    I'm having a difficult time with the Scrollbar component. I'm trying to have a scrollbar set up to navigate a text field or a MC of a text field. I managed to get it functioning within the desired frame, however when I jump to another frame, that very same content appears on the other frame, despite the fact that said frame did not have the scrollbar nor the content pasted within.
    The bar seems to do what I want it to do save for the unwelcomed presence outside of the frame of choice. Here's the code I'm using. This is the keyframe code:
    import boppreh.ui.Scrollbar
    var scrollbar1:Scrollbar = new Scrollbar(boomboom, 500, true, false, 293, bar, slider, arrowUp, arrowDown)
    addChild(scrollbar1)
    scrollbar1.x = 50
    scrollbar1.y = 50
    And this is the code found in the AS file:
    package boppreh.ui
        import flash.display.*
        import flash.events.*
        import flash.geom.Rectangle;
        import flash.utils.Timer
        import flash.ui.Keyboard
         * Scrollbar to handle single display objects.
         * Author: Lucas Boppre Niehues ([email protected])
         * Date: 09/02/2010
        public class Scrollbar extends Sprite {
            /// The default width for the default slider, bar and arrows, as well as the default arrows' height
            public static const DEFAULT_SIDE:Number = 20
            /// The delay (in milliseconds) between clicking and holding an arrow and the slider moving continously
            public static var SCROLL_DELAY:Number = 300
            /// The number of lines to be scrolled every second during continous scrolling
            public static var LINES_PER_SECOND:Number = 1.5
            /// Number of pixels to be scrolled for each mouse wheel line (default lines per wheel tick is 3)
            public static var PIXELS_PER_LINE:Number = 16
            protected var windowSize:Number
            protected var contentPadding:Number
            protected var isVertical:Boolean
            /// Stored movement to be applied on the next "scroll()" call
            protected var movement:Number
            /// Timer used to control the delay before continous scrolling
            protected var timer:Timer
            protected var content:DisplayObject
            protected var contentBounds:Rectangle
            protected var bar:InteractiveObject
            protected var arrowUp:InteractiveObject
            protected var arrowDown:InteractiveObject
            protected var slider:InteractiveObject
            protected var partHold:InteractiveObject
            protected function get eventOrigin():String {
                if (partHold == arrowUp)
                    return ScrollEvent.ARROW_UP
                else if (partHold == arrowDown)
                    return ScrollEvent.ARROW_DOWN
                else if (partHold == bar)
                    return ScrollEvent.BAR
                throw new Error("Unkown event origin.")
            private var mouseOffset:Number
            protected function get maxContentPos():Number {
                if (isVertical)
                    return -(contentBounds.height - windowSize) - 1
                else
                    return -(contentBounds.width - windowSize) - 1
            /// The content's current position, in a scale from 0 to 1
            public function get position():Number {
                if (isVertical)
                    return contentBounds.y / maxContentPos
                else
                    return contentBounds.x / maxContentPos
            public function set position(value:Number) {
                value = Math.min(1, Math.max(value, 0))
                var newContentPos:Number = value * maxContentPos
                setPosition(content, isVertical ? null : newContentPos, isVertical ? newContentPos : null, false, false)
                contentBounds = content.getBounds(this)
                if (isVertical) {
                    bar.height = windowSize - (arrowUp.height + arrowDown.height)
                    slider.height = (windowSize / Math.max(contentBounds.height, windowSize)) * bar.height
                    var newSliderY:Number = arrowUp.height + (-newContentPos / contentBounds.height) * bar.height
                    setPosition(slider, null, newSliderY, false, false)
                } else {
                    bar.width = windowSize - (arrowUp.width + arrowDown.width)
                    slider.width = (windowSize / Math.max(contentBounds.width, windowSize)) * bar.width
                    var newSliderX:Number = arrowUp.width + (-newContentPos / contentBounds.width) * bar.width
                    setPosition(slider, newSliderX, null, false, false)
                updatePartsPositions()
             * Creates a new Scrollbar object to scroll a single Display Object.
             * @param    content    the object to be scrolled
             * @param    windowSize    the height or width of the scrollbar, depending if it's vertical or not; i.e.: the dimension of the content's visible part
             * @param    isVertical    defines if the scrollbar's parts should be placed on the right or bottom of the content, and if the content should be scrolled upways or to the right
             * @param    autoUpdate    automatically checks for dimensions changes in any part and updates accordingly. Use only if the content will be resized
             * @param    contentPadding    the distance between the content and all the other parts
             * @param    bar    the bar object to be used; if null, a default one will be used
             * @param    slider    the slider object to be used; if null, a default one will be used
             * @param    arrowUp    the arrow up/left object to be used; if null, a default one will be used
             * @param    arrowDown    the arrow down/right object to be used; if null, a default one will be used
            public function Scrollbar(content:DisplayObject, windowSize:Number, isVertical:Boolean=true, autoUpdate:Boolean=false, contentPadding:Number=5, bar:InteractiveObject=null, slider:InteractiveObject=null, arrowUp:InteractiveObject=null, arrowDown:InteractiveObject=null) {
                this.content = content
                this.windowSize = windowSize
                this.contentPadding = contentPadding
                this.isVertical = isVertical
                this.bar = bar || createDefaultBar()
                this.arrowUp = arrowUp || createDefaultArrow(false)
                this.arrowDown = arrowDown || createDefaultArrow(true)
                this.slider = slider || createDefaultSlider()
                timer = new Timer(SCROLL_DELAY)
                timer.addEventListener(TimerEvent.TIMER, startScrolling)
                addParts()
                if (autoUpdate)
                    this.addEventListener(Event.ENTER_FRAME, update)
                configureListeners()
                update()
                position = 0
            protected function scroll(e:*= null):void {
                // This nested if forbids the slider to continue moving if the user is
                // "holding" the bar and the slider already reached the mouse position
                if (e && (e is Event) && (Event(e).type == Event.ENTER_FRAME)) {
                    if (partHold == bar) {
                        var sliderBounds:Rectangle = slider.getBounds(this)
                        if (isVertical) {
                            if (mouseY > sliderBounds.top && mouseY < sliderBounds.bottom) {
                                stopScrolling()
                                return
                        } else {
                            if (mouseX > sliderBounds.left && mouseX < sliderBounds.right) {
                                stopScrolling()
                                return
                scrollPixels(movement)
             * Scrolls the content by the specified ammount.
             * @param    number    number of pixels to be scrolled
            protected function scrollPixels(number:Number):void {
                position += number / -maxContentPos
            protected function configureListeners():void {
                slider.addEventListener(MouseEvent.MOUSE_DOWN, startSliderDrag)
                for each (var part:InteractiveObject in [arrowUp, arrowDown, bar]) {
                    part.addEventListener(MouseEvent.MOUSE_DOWN, fixedPart_onMouseDownHandler)
                addEventListener(MouseEvent.MOUSE_WHEEL, mouse_onWheelScrollHandler)
                addEventListener(KeyboardEvent.KEY_DOWN, keyboard_onKeyDownHandler)
            protected function fixedPart_onMouseDownHandler(event:MouseEvent):void
                partHold = InteractiveObject(event.currentTarget)
                if (partHold == arrowUp) {
                    movement = -PIXELS_PER_LINE
                } else if (partHold == arrowDown) {
                    movement = PIXELS_PER_LINE
                } else if (partHold == bar) {
                    var sliderBounds:Rectangle = slider.getBounds(this)
                    if (isVertical) {
                        if (mouseY > (sliderBounds.top + sliderBounds.height / 2))
                            movement = windowSize
                        else
                            movement = -windowSize
                    } else {
                        if (mouseX > (sliderBounds.left + sliderBounds.width / 2))
                            movement = windowSize
                        else
                            movement = -windowSize
                scroll()
                dispatchEvent(new ScrollEvent(ScrollEvent.SCROLL, eventOrigin))
                stage.addEventListener(MouseEvent.MOUSE_UP, stopScrolling)
                partHold.addEventListener(MouseEvent.MOUSE_OUT, stopScrolling)
                timer.start()
            protected function keyboard_onKeyDownHandler(event:KeyboardEvent):void {
                switch (event.keyCode) {
                    case Keyboard.UP:
                    case Keyboard.LEFT:
                        movement = -PIXELS_PER_LINE
                        break
                    case Keyboard.DOWN:
                    case Keyboard.RIGHT:
                        movement = PIXELS_PER_LINE
                        break
                    case Keyboard.SPACE:
                    case Keyboard.PAGE_DOWN:
                        movement = windowSize
                        break
                    case Keyboard.PAGE_UP:
                        movement = -windowSize
                        break
                    case Keyboard.HOME:
                        movement = 0
                        position = 0
                        break
                    case Keyboard.END:
                        movement = 0
                        position = 100
                        break
                    default:
                        return
                scroll()
                dispatchEvent(new ScrollEvent(ScrollEvent.SCROLL, ScrollEvent.KEYBOARD))
            protected function startScrolling(e:*=null):void {
                timer.reset()
                this.addEventListener(Event.ENTER_FRAME, scroll)
                movement = (movement * (LINES_PER_SECOND * PIXELS_PER_LINE)) / stage.frameRate
                dispatchEvent(new ScrollEvent(ScrollEvent.CONTINOUS_SCROLL_START, eventOrigin))
            protected function stopScrolling(e:*=null) {
                timer.stop()
                this.removeEventListener(Event.ENTER_FRAME, scroll)
                stage.removeEventListener(KeyboardEvent.KEY_UP, stopScrolling)
                stage.removeEventListener(MouseEvent.MOUSE_UP, stopScrolling)
                dispatchEvent(new ScrollEvent(ScrollEvent.CONTINOUS_SCROLL_STOP, eventOrigin))
                if (partHold) {
                    partHold.removeEventListener(MouseEvent.MOUSE_OUT, stopScrolling)
                    partHold = null
            protected function mouse_onWheelScrollHandler(event:MouseEvent) {
                // The mouse wheel delta arrives inverted
                var delta:int = -event.delta
                movement = delta * PIXELS_PER_LINE
                scroll()
                dispatchEvent(new ScrollEvent(ScrollEvent.SCROLL, ScrollEvent.MOUSE_WHEEL))
            //{ region Slider Drag functions
            protected function startSliderDrag(event:MouseEvent) {
                if (isVertical)
                    mouseOffset = slider.getBounds(this).y - this.mouseY
                else
                    mouseOffset = slider.getBounds(this).x - this.mouseX
                stage.addEventListener(MouseEvent.MOUSE_MOVE, onSliderDrag)
                stage.addEventListener(MouseEvent.MOUSE_UP, stopSliderDrag)
                dispatchEvent(new ScrollEvent(ScrollEvent.SLIDER_DRAG_START, ScrollEvent.SLIDER))
            protected function stopSliderDrag(event:MouseEvent) {
                stage.removeEventListener(MouseEvent.MOUSE_UP, stopSliderDrag)
                stage.removeEventListener(MouseEvent.MOUSE_MOVE, onSliderDrag)
                dispatchEvent(new ScrollEvent(ScrollEvent.SLIDER_DRAG_STOP, ScrollEvent.SLIDER))
            protected function onSliderDrag(event:MouseEvent) {
                if (isVertical) {
                    if (bar.height == slider.height)
                        return
                } else {
                    if (bar.width == slider.width)
                        return
                if (isVertical)
                    position = (this.mouseY + mouseOffset - arrowUp.height) / (bar.height - slider.height)
                else
                    position = (this.mouseX + mouseOffset - arrowUp.width) / (bar.width - slider.width)
            //} endregion
            //{ region Visual functions
            /// Adds all required parts to the scrollbar's display list
            protected function addParts():void {
                setPosition(content, 0, 0, false, false)
                addChild(this.bar)
                addChild(this.arrowUp)
                addChild(this.arrowDown)
                addChild(this.slider)
                addChild(this.content)
             * Updates all parts to fit the new dimensions and positions.
            public function update(e:*= null):void {
                contentBounds = content.getBounds(this)
                updatePartsPositions()
                // Ugly, but updates everything that was not update in the above call based on the content's position and size
                position = position
            protected function updatePartsPositions(event:Event = null):void {
                if (isVertical) {
                    // The parts width is divided by 2 because they will be center aligned
                    var newX:Number = contentBounds.width +
                                contentPadding +
                                Math.max(slider.width, arrowUp.width, arrowDown.width, bar.width) / 2
                    setPosition(arrowUp, newX, 0, true, false)
                    setPosition(bar, newX, arrowUp.height, true, false)
                    setPosition(arrowDown, newX, arrowUp.height + bar.height, true, false)
                    setPosition(slider, newX, null, true, false)
                } else {
                    var newY:Number = contentBounds.height +
                                contentPadding +
                                Math.max(slider.height, arrowUp.height, arrowDown.height, bar.height) / 2
                    setPosition(arrowUp, 0, newY, false, true)
                    setPosition(bar, arrowUp.width, newY, false, true)
                    setPosition(arrowDown, arrowUp.width + bar.width, newY, false, true)
                    setPosition(slider, null, newY, false, true)
                updateMask()
            private function updateMask():void {
                if (content.mask && this.contains(content.mask))
                    removeChild(content.mask)
                var contentMask:Sprite = createWindowMask()
                addChild(contentMask)
                content.mask = contentMask
            protected function setPosition(part:DisplayObject, newX:Object=null, newY:Object=null, alignHorizontal:Boolean=false, alignVertical:Boolean=false):void {
                var bounds:Rectangle = part.getBounds(this)
                if (newX is Number)
                    part.x = int(newX) + (part.x - bounds.x) - ((alignHorizontal) ? bounds.width / 2 : 0)
                if (newY is Number)
                    part.y = int(newY) + (part.y - bounds.y) - ((alignVertical) ? bounds.height / 2 : 0)
            //} endregion
            //{ region Functions to draw parts
            private function createDefaultBar():Sprite {
                var image:Sprite = new Sprite()
                image.graphics.lineStyle(1)
                image.graphics.beginFill(0xFFFFFF)
                if (isVertical)
                    image.graphics.drawRect(0, 0, DEFAULT_SIDE, windowSize - DEFAULT_SIDE * 2)
                else
                    image.graphics.drawRect(0, 0, windowSize - DEFAULT_SIDE * 2, DEFAULT_SIDE)
                image.graphics.endFill()
                //image.buttonMode = true
                return image
            private function createDefaultArrow(inverted:Boolean):Sprite {
                var image:Sprite = new Sprite()
                image.graphics.lineStyle(1)
                image.graphics.beginFill(0xBFBFBF)
                image.graphics.drawRect(0, 0, DEFAULT_SIDE, DEFAULT_SIDE)
                image.graphics.endFill()
                image.graphics.lineStyle(3)
                if (isVertical) {
                    if (inverted) {
                        image.graphics.moveTo(4, 4)
                        image.graphics.lineTo(10, 16)
                        image.graphics.lineTo(16, 4)
                    } else {
                        image.graphics.moveTo(4, 16)
                        image.graphics.lineTo(10, 4)
                        image.graphics.lineTo(16, 16)
                } else {
                    if (inverted) {
                        image.graphics.moveTo(4, 4)
                        image.graphics.lineTo(16, 10)
                        image.graphics.lineTo(4, 16)
                    } else {
                        image.graphics.moveTo(16, 4)
                        image.graphics.lineTo(4, 10)
                        image.graphics.lineTo(16, 16)
                image.buttonMode = true
                return image
            private function createDefaultSlider():Sprite {
                var image:Sprite = new Sprite()
                image.graphics.lineStyle(1)
                image.graphics.beginFill(0xBFBFBF)
                if (isVertical)
                    image.graphics.drawRect(0, 0, DEFAULT_SIDE, windowSize - DEFAULT_SIDE * 2)
                else
                    image.graphics.drawRect(0, 0, windowSize - DEFAULT_SIDE * 2, DEFAULT_SIDE)
                image.graphics.endFill()
                image.buttonMode = true
                return image
            private function createWindowMask():Sprite {
                var image:Sprite = new Sprite()
                image.graphics.lineStyle(0)
                image.graphics.beginFill(0x000000, 1)
                if (isVertical)
                    image.graphics.drawRect(0, 0, content.width + 1, windowSize)
                else
                    image.graphics.drawRect(0, 0, windowSize, content.width + 1)
                image.graphics.endFill()
                image.alpha = 0
                return image
            //} endregion
    And this is the ScrollEvent AS file:
    package boppreh.ui
        import flash.events.Event;
         * Events related to the Scrollbar class.
         * Author: Lucas Boppre Niehues ([email protected])
         * Date: 09/02/2010
        public class ScrollEvent extends Event
            /// Dispatched when a scroll movement occurs
            public static const SCROLL:String = "scroll"
            /// Dispatched when the user has clicked and is holding an arrow or the bar
            public static const CONTINOUS_SCROLL_START:String = "continous scroll start"
            /// Dispatched when the user has clicked and dropped an arrow or the bar
            public static const CONTINOUS_SCROLL_STOP:String = "continous scroll stop"
            /// Dispatched when the user starts dragging the slider part
            public static const SLIDER_DRAG_START:String = "slider drag start"
            /// Dispatched when the user stops dragging the slider part
            public static const SLIDER_DRAG_STOP:String = "slider drag stop"
            /// Origin type representing the arrow up part
            public static const ARROW_UP:String = "arrow up"
            /// Origin type representing the arrow down part
            public static const ARROW_DOWN:String = "arrow down"
            /// Origin type representing the bar part
            public static const BAR:String = "part"
            /// Origin type representing the slider part
            public static const SLIDER:String = "slider"
            /// Origin type representing the keyboard
            public static const KEYBOARD:String = "keyboard"
            /// Origin type representing the mouse wheel
            public static const MOUSE_WHEEL:String = "mouse wheel"
            public var origin:String
             * Creates a new ScrollEvent object.
             * @param    type    the object type (first group of declared constants)
             * @param    origin    the object that originated the event (second group of declared constants)
            public function ScrollEvent (type:String, origin:String, bubbles:Boolean = false, cancelable:Boolean = false) {
                this.origin = origin
                super(type, bubbles, cancelable)
    Any help would be appreciated. I've been stuck here all day.

    I'm having a difficult time with the Scrollbar component. I'm trying to have a scrollbar set up to navigate a text field or a MC of a text field. I managed to get it functioning within the desired frame, however when I jump to another frame, that very same content appears on the other frame, despite the fact that said frame did not have the scrollbar nor the content pasted within.
    The bar seems to do what I want it to do save for the unwelcomed presence outside of the frame of choice. Here's the code I'm using. This is the keyframe code:
    import boppreh.ui.Scrollbar
    var scrollbar1:Scrollbar = new Scrollbar(boomboom, 500, true, false, 293, bar, slider, arrowUp, arrowDown)
    addChild(scrollbar1)
    scrollbar1.x = 50
    scrollbar1.y = 50
    And this is the code found in the AS file:
    package boppreh.ui
        import flash.display.*
        import flash.events.*
        import flash.geom.Rectangle;
        import flash.utils.Timer
        import flash.ui.Keyboard
         * Scrollbar to handle single display objects.
         * Author: Lucas Boppre Niehues ([email protected])
         * Date: 09/02/2010
        public class Scrollbar extends Sprite {
            /// The default width for the default slider, bar and arrows, as well as the default arrows' height
            public static const DEFAULT_SIDE:Number = 20
            /// The delay (in milliseconds) between clicking and holding an arrow and the slider moving continously
            public static var SCROLL_DELAY:Number = 300
            /// The number of lines to be scrolled every second during continous scrolling
            public static var LINES_PER_SECOND:Number = 1.5
            /// Number of pixels to be scrolled for each mouse wheel line (default lines per wheel tick is 3)
            public static var PIXELS_PER_LINE:Number = 16
            protected var windowSize:Number
            protected var contentPadding:Number
            protected var isVertical:Boolean
            /// Stored movement to be applied on the next "scroll()" call
            protected var movement:Number
            /// Timer used to control the delay before continous scrolling
            protected var timer:Timer
            protected var content:DisplayObject
            protected var contentBounds:Rectangle
            protected var bar:InteractiveObject
            protected var arrowUp:InteractiveObject
            protected var arrowDown:InteractiveObject
            protected var slider:InteractiveObject
            protected var partHold:InteractiveObject
            protected function get eventOrigin():String {
                if (partHold == arrowUp)
                    return ScrollEvent.ARROW_UP
                else if (partHold == arrowDown)
                    return ScrollEvent.ARROW_DOWN
                else if (partHold == bar)
                    return ScrollEvent.BAR
                throw new Error("Unkown event origin.")
            private var mouseOffset:Number
            protected function get maxContentPos():Number {
                if (isVertical)
                    return -(contentBounds.height - windowSize) - 1
                else
                    return -(contentBounds.width - windowSize) - 1
            /// The content's current position, in a scale from 0 to 1
            public function get position():Number {
                if (isVertical)
                    return contentBounds.y / maxContentPos
                else
                    return contentBounds.x / maxContentPos
            public function set position(value:Number) {
                value = Math.min(1, Math.max(value, 0))
                var newContentPos:Number = value * maxContentPos
                setPosition(content, isVertical ? null : newContentPos, isVertical ? newContentPos : null, false, false)
                contentBounds = content.getBounds(this)
                if (isVertical) {
                    bar.height = windowSize - (arrowUp.height + arrowDown.height)
                    slider.height = (windowSize / Math.max(contentBounds.height, windowSize)) * bar.height
                    var newSliderY:Number = arrowUp.height + (-newContentPos / contentBounds.height) * bar.height
                    setPosition(slider, null, newSliderY, false, false)
                } else {
                    bar.width = windowSize - (arrowUp.width + arrowDown.width)
                    slider.width = (windowSize / Math.max(contentBounds.width, windowSize)) * bar.width
                    var newSliderX:Number = arrowUp.width + (-newContentPos / contentBounds.width) * bar.width
                    setPosition(slider, newSliderX, null, false, false)
                updatePartsPositions()
             * Creates a new Scrollbar object to scroll a single Display Object.
             * @param    content    the object to be scrolled
             * @param    windowSize    the height or width of the scrollbar, depending if it's vertical or not; i.e.: the dimension of the content's visible part
             * @param    isVertical    defines if the scrollbar's parts should be placed on the right or bottom of the content, and if the content should be scrolled upways or to the right
             * @param    autoUpdate    automatically checks for dimensions changes in any part and updates accordingly. Use only if the content will be resized
             * @param    contentPadding    the distance between the content and all the other parts
             * @param    bar    the bar object to be used; if null, a default one will be used
             * @param    slider    the slider object to be used; if null, a default one will be used
             * @param    arrowUp    the arrow up/left object to be used; if null, a default one will be used
             * @param    arrowDown    the arrow down/right object to be used; if null, a default one will be used
            public function Scrollbar(content:DisplayObject, windowSize:Number, isVertical:Boolean=true, autoUpdate:Boolean=false, contentPadding:Number=5, bar:InteractiveObject=null, slider:InteractiveObject=null, arrowUp:InteractiveObject=null, arrowDown:InteractiveObject=null) {
                this.content = content
                this.windowSize = windowSize
                this.contentPadding = contentPadding
                this.isVertical = isVertical
                this.bar = bar || createDefaultBar()
                this.arrowUp = arrowUp || createDefaultArrow(false)
                this.arrowDown = arrowDown || createDefaultArrow(true)
                this.slider = slider || createDefaultSlider()
                timer = new Timer(SCROLL_DELAY)
                timer.addEventListener(TimerEvent.TIMER, startScrolling)
                addParts()
                if (autoUpdate)
                    this.addEventListener(Event.ENTER_FRAME, update)
                configureListeners()
                update()
                position = 0
            protected function scroll(e:*= null):void {
                // This nested if forbids the slider to continue moving if the user is
                // "holding" the bar and the slider already reached the mouse position
                if (e && (e is Event) && (Event(e).type == Event.ENTER_FRAME)) {
                    if (partHold == bar) {
                        var sliderBounds:Rectangle = slider.getBounds(this)
                        if (isVertical) {
                            if (mouseY > sliderBounds.top && mouseY < sliderBounds.bottom) {
                                stopScrolling()
                                return
                        } else {
                            if (mouseX > sliderBounds.left && mouseX < sliderBounds.right) {
                                stopScrolling()
                                return
                scrollPixels(movement)
             * Scrolls the content by the specified ammount.
             * @param    number    number of pixels to be scrolled
            protected function scrollPixels(number:Number):void {
                position += number / -maxContentPos
            protected function configureListeners():void {
                slider.addEventListener(MouseEvent.MOUSE_DOWN, startSliderDrag)
                for each (var part:InteractiveObject in [arrowUp, arrowDown, bar]) {
                    part.addEventListener(MouseEvent.MOUSE_DOWN, fixedPart_onMouseDownHandler)
                addEventListener(MouseEvent.MOUSE_WHEEL, mouse_onWheelScrollHandler)
                addEventListener(KeyboardEvent.KEY_DOWN, keyboard_onKeyDownHandler)
            protected function fixedPart_onMouseDownHandler(event:MouseEvent):void
                partHold = InteractiveObject(event.currentTarget)
                if (partHold == arrowUp) {
                    movement = -PIXELS_PER_LINE
                } else if (partHold == arrowDown) {
                    movement = PIXELS_PER_LINE
                } else if (partHold == bar) {
                    var sliderBounds:Rectangle = slider.getBounds(this)
                    if (isVertical) {
                        if (mouseY > (sliderBounds.top + sliderBounds.height / 2))
                            movement = windowSize
                        else
                            movement = -windowSize
                    } else {
                        if (mouseX > (sliderBounds.left + sliderBounds.width / 2))
                            movement = windowSize
                        else
                            movement = -windowSize
                scroll()
                dispatchEvent(new ScrollEvent(ScrollEvent.SCROLL, eventOrigin))
                stage.addEventListener(MouseEvent.MOUSE_UP, stopScrolling)
                partHold.addEventListener(MouseEvent.MOUSE_OUT, stopScrolling)
                timer.start()
            protected function keyboard_onKeyDownHandler(event:KeyboardEvent):void {
                switch (event.keyCode) {
                    case Keyboard.UP:
                    case Keyboard.LEFT:
                        movement = -PIXELS_PER_LINE
                        break
                    case Keyboard.DOWN:
                    case Keyboard.RIGHT:
                        movement = PIXELS_PER_LINE
                        break
                    case Keyboard.SPACE:
                    case Keyboard.PAGE_DOWN:
                        movement = windowSize
                        break
                    case Keyboard.PAGE_UP:
                        movement = -windowSize
                        break
                    case Keyboard.HOME:
                        movement = 0
                        position = 0
                        break
                    case Keyboard.END:
                        movement = 0
                        position = 100
                        break
                    default:
                        return
                scroll()
                dispatchEvent(new ScrollEvent(ScrollEvent.SCROLL, ScrollEvent.KEYBOARD))
            protected function startScrolling(e:*=null):void {
                timer.reset()
                this.addEventListener(Event.ENTER_FRAME, scroll)
                movement = (movement * (LINES_PER_SECOND * PIXELS_PER_LINE)) / stage.frameRate
                dispatchEvent(new ScrollEvent(ScrollEvent.CONTINOUS_SCROLL_START, eventOrigin))
            protected function stopScrolling(e:*=null) {
                timer.stop()
                this.removeEventListener(Event.ENTER_FRAME, scroll)
                stage.removeEventListener(KeyboardEvent.KEY_UP, stopScrolling)
                stage.removeEventListener(MouseEvent.MOUSE_UP, stopScrolling)
                dispatchEvent(new ScrollEvent(ScrollEvent.CONTINOUS_SCROLL_STOP, eventOrigin))
                if (partHold) {
                    partHold.removeEventListener(MouseEvent.MOUSE_OUT, stopScrolling)
                    partHold = null
            protected function mouse_onWheelScrollHandler(event:MouseEvent) {
                // The mouse wheel delta arrives inverted
                var delta:int = -event.delta
                movement = delta * PIXELS_PER_LINE
                scroll()
                dispatchEvent(new ScrollEvent(ScrollEvent.SCROLL, ScrollEvent.MOUSE_WHEEL))
            //{ region Slider Drag functions
            protected function startSliderDrag(event:MouseEvent) {
                if (isVertical)
                    mouseOffset = slider.getBounds(this).y - this.mouseY
                else
                    mouseOffset = slider.getBounds(this).x - this.mouseX
                stage.addEventListener(MouseEvent.MOUSE_MOVE, onSliderDrag)
                stage.addEventListener(MouseEvent.MOUSE_UP, stopSliderDrag)
                dispatchEvent(new ScrollEvent(ScrollEvent.SLIDER_DRAG_START, ScrollEvent.SLIDER))
            protected function stopSliderDrag(event:MouseEvent) {
                stage.removeEventListener(MouseEvent.MOUSE_UP, stopSliderDrag)
                stage.removeEventListener(MouseEvent.MOUSE_MOVE, onSliderDrag)
                dispatchEvent(new ScrollEvent(ScrollEvent.SLIDER_DRAG_STOP, ScrollEvent.SLIDER))
            protected function onSliderDrag(event:MouseEvent) {
                if (isVertical) {
                    if (bar.height == slider.height)
                        return
                } else {
                    if (bar.width == slider.width)
                        return
                if (isVertical)
                    position = (this.mouseY + mouseOffset - arrowUp.height) / (bar.height - slider.height)
                else
                    position = (this.mouseX + mouseOffset - arrowUp.width) / (bar.width - slider.width)
            //} endregion
            //{ region Visual functions
            /// Adds all required parts to the scrollbar's display list
            protected function addParts():void {
                setPosition(content, 0, 0, false, false)
                addChild(this.bar)
                addChild(this.arrowUp)
                addChild(this.arrowDown)
                addChild(this.slider)
                addChild(this.content)
             * Updates all parts to fit the new dimensions and positions.
            public function update(e:*= null):void {
                contentBounds = content.getBounds(this)
                updatePartsPositions()
                // Ugly, but updates everything that was not update in the above call based on the content's position and size
                position = position
            protected function updatePartsPositions(event:Event = null):void {
                if (isVertical) {
                    // The parts width is divided by 2 because they will be center aligned
                    var newX:Number = contentBounds.width +
                                contentPadding +
                                Math.max(slider.width, arrowUp.width, arrowDown.width, bar.width) / 2
                    setPosition(arrowUp, newX, 0, true, false)
                    setPosition(bar, newX, arrowUp.height, true, false)
                    setPosition(arrowDown, newX, arrowUp.height + bar.height, true, false)
                    setPosition(slider, newX, null, true, false)
                } else {
                    var newY:Number = contentBounds.height +
                                contentPadding +
                                Math.max(slider.height, arrowUp.height, arrowDown.height, bar.height) / 2
                    setPosition(arrowUp, 0, newY, false, true)
                    setPosition(bar, arrowUp.width, newY, false, true)
                    setPosition(arrowDown, arrowUp.width + bar.width, newY, false, true)
                    setPosition(slider, null, newY, false, true)
                updateMask()
            private function updateMask():void {
                if (content.mask && this.contains(content.mask))
                    removeChild(content.mask)
                var contentMask:Sprite = createWindowMask()
                addChild(contentMask)
                content.mask = contentMask
            protected function setPosition(part:DisplayObject, newX:Object=null, newY:Object=null, alignHorizontal:Boolean=false, alignVertical:Boolean=false):void {
                var bounds:Rectangle = part.getBounds(this)
                if (newX is Number)
                    part.x = int(newX) + (part.x - bounds.x) - ((alignHorizontal) ? bounds.width / 2 : 0)
                if (newY is Number)
                    part.y = int(newY) + (part.y - bounds.y) - ((alignVertical) ? bounds.height / 2 : 0)
            //} endregion
            //{ region Functions to draw parts
            private function createDefaultBar():Sprite {
                var image:Sprite = new Sprite()
                image.graphics.lineStyle(1)
                image.graphics.beginFill(0xFFFFFF)
                if (isVertical)
                    image.graphics.drawRect(0, 0, DEFAULT_SIDE, windowSize - DEFAULT_SIDE * 2)
                else
                    image.graphics.drawRect(0, 0, windowSize - DEFAULT_SIDE * 2, DEFAULT_SIDE)
                image.graphics.endFill()
                //image.buttonMode = true
                return image
            private function createDefaultArrow(inverted:Boolean):Sprite {
                var image:Sprite = new Sprite()
                image.graphics.lineStyle(1)
                image.graphics.beginFill(0xBFBFBF)
                image.graphics.drawRect(0, 0, DEFAULT_SIDE, DEFAULT_SIDE)
                image.graphics.endFill()
                image.graphics.lineStyle(3)
                if (isVertical) {
                    if (inverted) {
                        image.graphics.moveTo(4, 4)
                        image.graphics.lineTo(10, 16)
                        image.graphics.lineTo(16, 4)
                    } else {
                        image.graphics.moveTo(4, 16)
                        image.graphics.lineTo(10, 4)
                        image.graphics.lineTo(16, 16)
                } else {
                    if (inverted) {
                        image.graphics.moveTo(4, 4)
                        image.graphics.lineTo(16, 10)
                        image.graphics.lineTo(4, 16)
                    } else {
                        image.graphics.moveTo(16, 4)
                        image.graphics.lineTo(4, 10)
                        image.graphics.lineTo(16, 16)
                image.buttonMode = true
                return image
            private function createDefaultSlider():Sprite {
                var image:Sprite = new Sprite()
                image.graphics.lineStyle(1)
                image.graphics.beginFill(0xBFBFBF)
                if (isVertical)
                    image.graphics.drawRect(0, 0, DEFAULT_SIDE, windowSize - DEFAULT_SIDE * 2)
                else
                    image.graphics.drawRect(0, 0, windowSize - DEFAULT_SIDE * 2, DEFAULT_SIDE)
                image.graphics.endFill()
                image.buttonMode = true
                return image
            private function createWindowMask():Sprite {
                var image:Sprite = new Sprite()
                image.graphics.lineStyle(0)
                image.graphics.beginFill(0x000000, 1)
                if (isVertical)
                    image.graphics.drawRect(0, 0, content.width + 1, windowSize)
                else
                    image.graphics.drawRect(0, 0, windowSize, content.width + 1)
                image.graphics.endFill()
                image.alpha = 0
                return image
            //} endregion
    And this is the ScrollEvent AS file:
    package boppreh.ui
        import flash.events.Event;
         * Events related to the Scrollbar class.
         * Author: Lucas Boppre Niehues ([email protected])
         * Date: 09/02/2010
        public class ScrollEvent extends Event
            /// Dispatched when a scroll movement occurs
            public static const SCROLL:String = "scroll"
            /// Dispatched when the user has clicked and is holding an arrow or the bar
            public static const CONTINOUS_SCROLL_START:String = "continous scroll start"
            /// Dispatched when the user has clicked and dropped an arrow or the bar
            public static const CONTINOUS_SCROLL_STOP:String = "continous scroll stop"
            /// Dispatched when the user starts dragging the slider part
            public static const SLIDER_DRAG_START:String = "slider drag start"
            /// Dispatched when the user stops dragging the slider part
            public static const SLIDER_DRAG_STOP:String = "slider drag stop"
            /// Origin type representing the arrow up part
            public static const ARROW_UP:String = "arrow up"
            /// Origin type representing the arrow down part
            public static const ARROW_DOWN:String = "arrow down"
            /// Origin type representing the bar part
            public static const BAR:String = "part"
            /// Origin type representing the slider part
            public static const SLIDER:String = "slider"
            /// Origin type representing the keyboard
            public static const KEYBOARD:String = "keyboard"
            /// Origin type representing the mouse wheel
            public static const MOUSE_WHEEL:String = "mouse wheel"
            public var origin:String
             * Creates a new ScrollEvent object.
             * @param    type    the object type (first group of declared constants)
             * @param    origin    the object that originated the event (second group of declared constants)
            public function ScrollEvent (type:String, origin:String, bubbles:Boolean = false, cancelable:Boolean = false) {
                this.origin = origin
                super(type, bubbles, cancelable)
    Any help would be appreciated. I've been stuck here all day.

  • Problem with Horizontal Scroll on java.awt.List

    I use the same code for a General Application as a CDC Application.
    I have no problem at all with the General Application but on the CDC I can't scroll to the right (horizontal).
    Why do I get this problem on the CDC application and not on a regular application?
    I use the PP-1.0 Profile for the CDC application. Does it not support horizontal scroll on java.awt.List?
    This is the code:
    * Main.java
    * Created on den 22 augusti 2007, 10:52
    package cdcapplication6;
    * @author  Erik Rothman
    public class Main extends java.awt.Frame {
        /** Creates new form Main */
        public Main() {
            initComponents();
              for (int i = 0; i < 10; i++) {
                   list1.add("Short text");
                   list1.add("Some very long text indeed. Some very long text indeed.");
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            list1 = new java.awt.List();
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            add(list1, java.awt.BorderLayout.CENTER);
            pack();
        }// </editor-fold>                       
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {                         
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Main().setVisible(true);
        // Variables declaration - do not modify                    
        private java.awt.List list1;
        // End of variables declaration                  
    }

    I use the same code for a General Application as a CDC Application.
    I have no problem at all with the General Application but on the CDC I can't scroll to the right (horizontal).
    Why do I get this problem on the CDC application and not on a regular application?
    I use the PP-1.0 Profile for the CDC application. Does it not support horizontal scroll on java.awt.List?
    This is the code:
    * Main.java
    * Created on den 22 augusti 2007, 10:52
    package cdcapplication6;
    * @author  Erik Rothman
    public class Main extends java.awt.Frame {
        /** Creates new form Main */
        public Main() {
            initComponents();
              for (int i = 0; i < 10; i++) {
                   list1.add("Short text");
                   list1.add("Some very long text indeed. Some very long text indeed.");
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            list1 = new java.awt.List();
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            add(list1, java.awt.BorderLayout.CENTER);
            pack();
        }// </editor-fold>                       
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {                         
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Main().setVisible(true);
        // Variables declaration - do not modify                    
        private java.awt.List list1;
        // End of variables declaration                  
    }

  • How To Add scrollbar in Spark list which will work on mouse movement ?

    Hi,
    I want to add scrollbar in Spark list which will work on mouse movement, i.e instead scrolling down it will sense mouse position and scroll automatically. I could not find a way to handle this with horizontalLayout.
    I tried hovering on list and setting ensureIndexIsVisible(index) but hovering element index is not present in the Spark List.
    Any idea on this will be highly appreciated.
    Thanks in advance
    Avishek

    Hi,
    I want to add scrollbar in Spark list which will work on mouse movement, i.e instead scrolling down it will sense mouse position and scroll automatically. I could not find a way to handle this with horizontalLayout.
    I tried hovering on list and setting ensureIndexIsVisible(index) but hovering element index is not present in the Spark List.
    Any idea on this will be highly appreciated.
    Thanks in advance
    Avishek

  • Scrollbar in awt

    how to control scrolling of 50 textfields using independent scrollbar in AWT?

    extend Panel
    setlayout to GridLayout (dimensions how many components you want)
    make an array of components.
    if the scrollbar fires an adjustmentevent put the "right" components on your panel.
    take care that you don't do any adding if you display the correct component anyway (scrollbars tend to fire more events then necessary)
    i have done that and it works well but i fear i can't send you the code since i think its property of the company i work for. If you are desperate enough to buy the code mail me at [email protected] and i talk to my boss.

  • Problem In Awt List

    I am Having problem with Awt List component
    setSize
    setPrefferedSize
    setMaximumSize
    None is working I have limited screen are to use in applet Hence I want to limit the width of List
    Below Is My code I am using in Devloping Some Applet.
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.List;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    public class ListSizeProblem extends Frame {
         public List list1;
         ListSizeProblem (String t) {
              this.setTitle(t); // setting up the main window
              this.setSize(500, 400);
              this.setLocation(50, 50);
              this.setLayout(new BorderLayout());
              addWindowListener(new WindowAdapter() { // application will exit if window is closed
                 public void windowClosing(WindowEvent e) {
                      System.exit(0);
              list1 = new List(15, false);
              //list1.setSize(new Dimension(40,200));
              list1.setPreferredSize(new Dimension(40,200));
              //list1.setMaximumSize(new Dimension(40,200));
               for (int i = 1; i < 21; i++) {
                 list1.add("But"+i);
              this.add(list1,BorderLayout.WEST);
              this.pack();
              this.setVisible(true);
         public static void main (String [] args) {
              ListSizeProblem mainframe = new ListSizeProblem("List Size");
    }can somebody help me

    It is indeed a bug. Once your List has data in it, the getPreferredSize method starts calling preferredSize(int rows) method. This method in turn asks the list's peer for the size. The result is that the preferred size you set is completely ignored (hence a bug). Quick fix would be to override the getPreferredSize method like so.
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.List;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    public class ListSizeProblem extends Frame {
        public List list1;
        ListSizeProblem(String t) {
            this.setTitle(t); // setting up the main window
            this.setSize(500, 400);
            this.setLocation(50, 50);
            this.setLayout(new BorderLayout());
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            list1 = new List(15, false) {
                Dimension size = new Dimension(40, 200);
                public java.awt.Dimension getPreferredSize() {
                    return size;
            for (int i = 1; i < 21; i++) {
                list1.add("But" + i);
            this.add(list1, BorderLayout.WEST);
            this.setVisible(true);
        public static void main(String[] args) {
            ListSizeProblem mainframe = new ListSizeProblem("List Size");
    }The list is not 200 pixels high, but this just comes from the fact that you don't have a BorderLayout.NORTH or BorderLayout.SOUTH object yet, so the BorderLayout is alowed to extend the height of the list.
    And you seem to havea pretty exact idea on the size you want your components to be. If the frame is not going to be resizable, then you can use no layout manager if you want. This would require you to set the exact bounds of every component you add to the frame.

  • Some problems in "AWT.List', Pls help !

    Dear all,
    Now i am studying a 'AWT.List'. I would like to know that how can i auto-swap the content on the 'AWT.List' into 2 or 3 line if the length of content is longer than the width of 'AWT.List'. And if it can be implemented, what is the return value of the specific rows ?
    Lung,
    Thx !

    As far as I know, List doesn't allow you to do that kind of thing. However, it could be pretty easily done with a JList and a JTextArea as ListCellRenderer.

  • How can i clear the textfield and the list selections?

    How can i clear the textfield and the list selections?
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    <applet code="ListDemo" width=300 height=400>
    </applet>
    public class ListDemo extends Applet implements ActionListener {
    List os, browser;
    String msg = "";
    String text;
    String named = "";
    TextField name;
    Button Ok, reset;
    public void init() {
    Ok = new Button("Ok");
    reset = new Button("reset");
    add(reset);
    add(Ok);
    reset.addActionListener(this);
    Ok.addActionListener(this);
    Label namep = new Label("Name: ", Label.RIGHT);
    name = new TextField(12);
    add(namep);
    add(name);
    name.addActionListener(this);
    os = new List(4, false);
    browser = new List(4, false);
    os.add("default");
    os.add("BMW");
    os.add("BENZ");
    os.add("Lexus");
    os.add("Acura");
    browser.add("default");
    browser.add("Red");
    browser.add("Black");
    browser.add("Silver");
    browser.add("Blue");
    browser.add("Yellow");
    browser.add("Pink");
    browser.add("Grey");
    browser.add("Blue/Black");
    os.select(0);
    browser.select(0);
    add(os);
    add(browser);
    os.addActionListener(this);
    browser.addActionListener(this);
    public void actionPerformed(ActionEvent ae) {
    String str = ae.getActionCommand();
    if(str.equals("Ok")){
    text = "You pressed Ok";
    else
    if(str.equals("reset")){
    browser.select(0);
    os.select(0);
    text = "";
    repaint();
    public void paint(Graphics g) {
    g.drawString("Name: " + name.getText(), 6, 120);
    int idx[];
    msg = "Current Car: ";
    idx = os.getSelectedIndexes();
    for(int i=0; i<idx.length; i++)
    msg += os.getItem(idx) + " ";
    g.drawString(msg, 6, 140);
    msg = "Current Color: ";
    msg += browser.getSelectedItem();
    g.drawString(msg, 6, 160);
    g.drawString(text, 6, 200);

    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    <applet code="ListDemo" width=300 height=400>
    </applet>
    public class ListDemo extends Applet implements ActionListener {
    List os, browser;
    String msg = "";
    String text;
    String named = "";
    TextField name;
    Button Ok, reset;
    public void init() {
    Ok = new Button("Ok");
    reset = new Button("reset");
    add(reset);
    add(Ok);
    reset.addActionListener(this);
    Ok.addActionListener(this);
    Label namep = new Label("Name: ", Label.RIGHT);
    name = new TextField(12);
    add(namep);
    add(name);
    name.addActionListener(this);
    os = new List(4, false);
    browser = new List(4, false);
    os.add("default");
    os.add("BMW");
    os.add("BENZ");
    os.add("Lexus");
    os.add("Acura");
    browser.add("default");
    browser.add("Red");
    browser.add("Black");
    browser.add("Silver");
    browser.add("Blue");
    browser.add("Yellow");
    browser.add("Pink");
    browser.add("Grey");
    browser.add("Blue/Black");
    os.select(0);
    browser.select(0);
    add(os);
    add(browser);
    os.addActionListener(this);
    browser.addActionListener(this);
    public void actionPerformed(ActionEvent ae) {
    String str = ae.getActionCommand();
    if(str.equals("Ok")){
    text = "You pressed Ok";
    else
    if(str.equals("reset")){
    browser.select(0);
    os.select(0);
    text = "";
    name.setText("");
    repaint();
    public void paint(Graphics g) {
    g.drawString("Name: " + name.getText(), 6, 120);
    int idx[];
    msg = "Current Car: ";
    idx = os.getSelectedIndexes();
    for(int i=0; i<idx.length; i++)
    msg += os.getItem(idx) + " ";
    g.drawString(msg, 6, 140);
    msg = "Current Color: ";
    msg += browser.getSelectedItem();
    g.drawString(msg, 6, 160);
    g.drawString(text, 6, 200);

  • Display image in java.awt.List

    hello guys,
    How i can display image in java.awt.List means listbox. give me sample code. if you have
    Waiting for your favorable reply.
    Regards,
    Bhavesh Kharwa

    java.awt.List you can not.
    javax.swing.JLast you can.

  • Plug-in for bullets and numbered lists in Mail??

    Does anyone know of any plug-ins for the Mail app to do bullets and numbered lists like Entourage??
    The lack of this functionality really makes Mail kinda lame and unusable for me.
    Thanks!

    Paul,
    the fact that Mail does not support bullit lists is not an oversight but was done on purpose. It may look good on your computer when you compose the message, but you have little influence in the way recipients see that message. It can get very messy, I can assure you.
    If you want a perfect layout, compose in a wordprocessor and save as PDF, send that as an attachment.

  • Difference between Combo Box and Dropdown List

    Hi All,
    I would like to know the difference between the elements 'Combo box' and 'Dropdown List' in VC. I am facing an issue where i am invoking an entry list and the output of the first element the entry list returns is getting reflected as the output for all the elements...
    So even if 2nd and 3rd row of the o/p from the entry list is giving only 2 items, if the 1st row returns only 1 then we are able to see only 1 item. Its as if the 1st row decides the items to be returned for all the rows.
    Please help.

    Hi Hezi,
    I have 2 columns in my table. First column is 'material number' and the 2nd one is 'production version'. There can 1,2 or 3 production version for each material. [This information is stored in the backend] This is retrieved through a method which invokes a bapi which in turn retrieves from the backend.
    I have provided a dropdown list for the 'production version' column. Lets say there are 2 rows. Material 1 and material 2. Lets say material 1 has 1 production version and material 2 has 2 production version. So rightfully speaking i should have 1 option in the dropdown for material 1 and 2 for material 2.
    But what i seeing is only 1 option for both the materials. This is wrong.
    Is there something that can be done to ensure that each row reflects the correct no. of options in the dropdown?

  • Is there any way to find number of addresses in to and cc list before fetch

    Hi,
    I am fetchig mails using IMAP.
    I want to fetch from,to cc addresses for each mail.
    But i foung a mail in my account having 35690 email addresses in to list.
    So fetching all these addresses is not worth full for me.
    So is there any way to find how many addresses are there in to and cc list before actually fetching them?
    Thanks in advance.
    -Prashanth.

    No.

  • How do I get a new email account to show in accounts and mailbox list

    I have added a new email account to my iPod OS5 but I can't access it.  It doesn't show up in my mailbox or account list.  How do I ge this new account to show up in these lists so that I can access the account?

    I tried a reset and it didn't help.  I have already added one gmail account and it shows up in both my "inboxes" and "Accounts" list.  Still can't access my second gmail account.  When I try to add the new gmail account again, I get the message that this account has already been created.  I have deleted the account and added it again with the same problem resulting.  Any other suggestions?

Maybe you are looking for

  • Help! Zen Micro stops in the middle of rebuilding- missing half of mus

    My Zen froze a few days ago. I went to reset it like I always do, but this time when it was rebuilding, it stopped about half way through.. starting making this clicking noise and then went back to the now playing screen. But now i am missing like ha

  • Resizing window affects data aquisition

    Hi Guys, got a really annoying problem that I've been trying to solve for about 2 weeks now, I'm hoping someone will be able to help me. We communicate through a dll to our data aquisition box (custom). Our custom data aquisition box has an array whi

  • Problem pool weblogic 6.1 and oracle thin driver 8.1.7

    Hi! I have a problem with CLOB column in Oracle 8.1.7. My enviroment is: Windows 2000, BEA WLS 6.1 and Oracle 8.1.7. I'm trying to use 'classes12.zip' provided by Oracle. I added 'classes12.zip' to CLASSPATH after than 'weblogic.jar' in my startup se

  • Two questions on apex_item.text when date field

    Hi, I have a tabular collection with a date field. I need to have validation on the date field, so wanted to create and authorization (is this the best way). In order to do so, I needed to create an application item (again...is this the best way?). I

  • X-Axis Labels BETWEEN Bars on Histogram?

    Is it possible to put x-axis labels between the bars of a histogram in Numbers? It becomes ambiguous in a chart like this (see photo) when the labels are directly below the frequency bar. For instance, looking at the bar above 1, did 14.44% of the we