Scrollbar help~
hi..
the code below are in working condition.. means can be compiled & run.. when drag the scrollbar, the "Welcome To Java" string message will be move left, right or up, down depend on which scrollbar u drag..
just wanna ask if the "Welcome To Java" text be changed to image?? so instead of the text shifting.. its the image tt is moving.. can anyone help me.. ??
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ScrollbarDemo extends Applet implements AdjustmentListener
//declare scrollbars
Scrollbar scbHort, scbVert;
//declare a canvas
ScrollMessageCanvas c;
public static void main(String[] args)
ScrollbarDemo f = new ScrollbarDemo();
f.setSize(300,200);
f.setVisible(true);
public ScrollbarDemo()
setLayout(new BorderLayout());
//create scrollbars
scbVert = new Scrollbar();
scbVert.setOrientation(Scrollbar.VERTICAL);
scbHort = new Scrollbar();
scbHort.setOrientation(Scrollbar.HORIZONTAL);
add("Center", c = new ScrollMessageCanvas());
add("East", scbVert);
add("South", scbHort);
//register listener for the scrollbars
scbHort.addAdjustmentListener(this);
scbVert.addAdjustmentListener(this);
public void adjustmentValueChanged(AdjustmentEvent e)
if(e.getSource() == scbHort)
/*getValue() and getMaximumValue() return int, but for better precision, use double*/
double value = scbHort.getValue();
double maximumValue = scbHort.getMaximum();
double newX = (value*c.getSize().width/maximumValue);
c.setX((int)newX);
else if(e.getSource() == scbVert)
/*getValue() and getMaximumValue() return int, but for better precision, use double*/
double value = scbVert.getValue();
double maximumValue = scbVert.getMaximum();
double newY = (value*c.getSize().height/maximumValue);
c.setY((int)newY);
class ScrollMessageCanvas extends Canvas
private int x = 10;
private int y = 20;
private String message = "Welcome to Java!";
public ScrollMessageCanvas()
repaint();
public void setX(int x)
this.x = x;
repaint();
public void setY(int y)
this.y = y;
repaint();
public void paint(Graphics g)
g.drawString(message, x, y);
}
what should i replace this line with??
[[ private String message = "Welcome to Java!"; ]]
public void paint(Graphics g)
g.drawString(message, x, y);
can be replaced by
public void paint(Graphics g)
g.drawImage(image, 0,0);
}
Similar Messages
-
Hello.
I am trying to build a webpage with a fixed sized window in
the centre of the page. Within this window I would like to display
some photos I have taken. What I would like to happen is for people
to be able to scroll right to view my pictures, but for the main
navigation not to disapear. So I thought I could incorporate a
horazontal scrollbar into the central box, so that whatever content
is in the box is scrollable. I have noticed things called div tags
and I think that this is the way forward, although I don't seem to
be able to use these effectivly.
Can anybody help me please.
Thanks
SThe scrollbar works, you can try using a simple JComponent with a set preferred size instead of the JTextPane and it will work. The problem is that the JTextPane always wraps its lines, so it doesn't need to be wider - therefore the scrollbar doesn't appear (or doesn't display the knob in case it's always displayed). You'll have to find a way to somehow disable line wrapping in that JTextPane, or you'll have to use another component to display your data, for example JTable.
-
Hello! Does anyone know any decent AS2 custom scrollbar tutorials? I'm looking to create a basic scrollbar that has a white up arrow and a white down arrow, but none of the tutorials I've tried end up working properly..... I've done way more complex stuff without any issues, so I don't know why I'm having so much trouble with scrollbars. Any help or suggestions would be much appreciated!
Thank you,
NicoleThanks! unfortunately you have to shell out $20 to view the tutorial found on that web page, but I did find another one that worked after I played around with it for a very, very long time. I'll post it incase anyone else would find it useful:
http://www.kirupa.com/developer/flash8/scrollbar.htm
After I altered the colors, content, and sizing, I saved the scroll area as it's own .swf. I then loaded it as an external movie clip into another page on my Flash site and it worked perfectly! -
Scrollbar Help Appreciated!
Hello everyone, this is my first post and was hoping for some
advice.
I am fairly new to Flash, I have no idea about Actionscript,
a part from stop();
I have designed a button that when you put your mouse over,
it slides out using a motion tween to reveal a panel with thumbnail
pictures. However, I need to make the panel scroll downwards to fit
all of the pictures on. When I click on the pictures, I want it to
take me to the relevant frame.
Please could someone point me in the right direction as to
how I could do this, links anything!
Many thanks,
HelenYou could try to put the two trees into a ScrolledComposite.
This way they should always have enough space available and probably
won't display their own scrollbar.
See the SWT teams Snippets page for an exmaple how to use ScrolledComposite.
Yves
exquisitus wrote:
> Hi - I have 2 trees side by side in a composite. I want both to use only
> the composite (vertical) scrollbar as oppose to each using their own.
> I've tried setVisible(false) but as soon as a resizing takes place the
> scrollbar appears plus this does not force it to use its parent. Is
> there a way of forcing a Tree Widget to use its Parent scrollBar. Any
> help appreciated.
> -
Web pages are missing their default scrollbars - help
Web pages are missing their scroll bars.
To be clear — I can create scroll bars for any element
within a page — no problem.
It’s that each pg itself which by default should come with its own scrollbars has none.
So if a viewer can’t see the entire page the viewer has no means to
horizontally or vertically scroll to see the off-screen portion of the page.
I’ve talk to the adobe tech support about the scroll-less pages.
They said the problem is beyond their expertise and lies in the code itself.
They advised me to reach across this platform for the answer.
The problem is consistent on all browsers.
I ran the pages thru Dreamweaver’s browsers’ lab. Pages varied slightly with each
Browsers, on the whole looked good. BUT a portion of the image on the right side
was cut off and the scrollbars were not available on the Adobe Browsers Test Lab page.
No errors were found when run thru Dreamweaver’s Browser Compatibility.
I reviewed the code but I have no idea what I’m looking for.
See For Yourself, the website with no scrollbars: voicesforthearts.com
Howard Blume
[email protected]
max os x system10.6.6
Dreamweaver 5While you are at it Howard, I noticed a METATAG in your BODY section.... it's already in the HEAD section.
<div id="logonavbar">
<ul>
<li><meta name="description" content="" /> -
The items in the list are being generated from an XML file.
At the moment, I only have 5 in the list because that's all that
would fit. What I want to do is have a scrollable list in that
area, so that my XML file could list many more than 5 items.
I'm not sure where to begin. I've done searches online, but
they don't seem to be what I'm looking for. What makes it more
complicated is that those items in the list are dynamically created
from a "linkaged" movie clip in the project library.
Any help would be appreciated. Even if it's just a point in
the right direction. Thanks.Rob - The items in the list are dynamically created movie
clips that contain two dynamic text fields (title, short
description) and a transparent hit area. This isn't going to help,
but thanks for the thought.
At the moment, I'm thinking that I could create the list in a
separate SWF and then "import" it in a scrollpane placed in the
original SWF. This isn't preferable to me, though, because I'd
rather keep it all self-contained. If I'm barking-up the wrong
tree, let me know, please! -
ScrollBar HELP Needed!!!
Hello,
I am developing a swing front end, however the size of the screen has grown quite large and at low resolutions I cant see some areas of the JFrame.
I need to be able to add a JScrollBar to the JFrame so that I will be able to scroll down to the parts of the screen which dissapear off the monitor.
Can anyone tell me how to do this??? I REALLY am stuck here! Thanks in advance.1. Post swing questinos in the Swing area.
2. Add the scrollpane to the frame the other way around.
import java.awt.*;
import javax.swing.*;
public class ScrollPaneDemo extends JFrame
public ScrollPaneDemo()
super( "Scroll Demo");
setDefaultCloseOperation( EXIT_ON_CLOSE );
JPanel panel = new JPanel( new GridLayout( 20, 20 ) );
for( int i = 0; i < 400; i++ )
JLabel label = new JLabel( "Row = "+ i/20 +" col = "+i%20 );
label.setBorder( BorderFactory.createLineBorder( Color.black ) );
panel.add( label);
setContentPane( new JScrollPane( panel ) );
setSize( 200, 200 );
setLocationRelativeTo( null );
setVisible( true );
public static void main( String[] args )
new ScrollPaneDemo();
} -
Hello,
I have a JSP page that shows a data list. IE scrollbar helps to show all the daat down. I want to fix the labels and make only the data scrollable. Can anyone help me?
Thanksthis is not a JSP problem but an HTML layout problem.
ANyway there are 4 solutions i can think of.
USe a frameset, 1 frame for the labels and 1 for the data
Use a Div with a overflow enabled (will add a srollbar to the div if needed
Use an iframe to display your data
Draw your labels in an DIV , put it into a seperate layer and make it fixed. -
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. -
hu..
i have this JFrane that has a table which has scrollbars...
i have included in my code setResizable(false) so the user will not be able to maximize the page..
i have a function AdScroll()[that adds scrollbars] that will be called every time i add ,delete ,update a user ..
my problem is when i click on the delete and update buttons the user will not be deleted or updated from the table, but when i remove AddScroll() the user will be deleted and updated from the table but the scroll bars will not be added..
so can some one help me with this problem.
thankx
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.sql.*;
import java.io.*;
import javax.swing.JPanel;
import java.applet.*;
import sun.audio.*;
import java.net.*;
import java.text.*;
class UtilityMethods extends JFrame implements ActionListener
private boolean tabsVisible=false;
private File fileName;
private RandomAccessFile output;
AudioStream voice;
UtilityMethods utilities;
Connection conn;
Statement stat;
String dsnName, userStatus;
String appTable = "CUSTOMER";
Container c = getContentPane();
JTabbedPane tabs;
//JScrollPane scrollpane;
JTable dataTable, addataTable;
static String[][] tableData, adtableData;
JScrollPane scrollpane, adscrollpane,vscrollpane;
JTextField id, name, address, phone, sex, dob, photo,audio,template;
JTextArea comments;
JButton search, update, clear, add, delete, close,audio1,faceBrowse,voiceBrowse,voice1;
JPanel customerPanel, adminPanel;
JPanel backPanel, inputPanel, middlePanel, buttonPanel1, buttonPanel2, photoHolder;
JTextField adname, adusername, adpassword;
JPanel adbackPanel, adinputPanel, admiddlePanel, adbuttonPanel1, adbuttonPanel2, radioPanel;
JButton adsearch, adupdate, adclear, adadd, addelete, adclose;
JRadioButton userStat, adminStat, cleared;
ButtonGroup statusGroup;
//===================================================================================================
/*public UtilityMethods()
makeGUI();
//Create the GUI:
void makeGUI()
c.setLayout(new BorderLayout());
tabs = new JTabbedPane();
customerPanel = new JPanel(new BorderLayout());
adminPanel = new JPanel(new BorderLayout());
// voicePanel= new JPanel(new BorderLayout());
//1. Construct customers tab:
//The data input section:
inputPanel = new JPanel(new GridLayout(4, 4));
id = new JTextField(20);
name = new JTextField(20);
address = new JTextField(20);
phone = new JTextField(20);
sex = new JTextField(20);
dob = new JTextField(20);
photo = new JTextField(20);
audio = new JTextField(20);
template = new JTextField(20);
faceBrowse = new JButton("...");
faceBrowse.setBounds(210, 150, 25, 25);
inputPanel.add(new JLabel("CPR", JLabel.CENTER));
inputPanel.add(id);
inputPanel.add(new JLabel("Name", JLabel.CENTER));
inputPanel.add(name);
inputPanel.add(new JLabel("Address", JLabel.CENTER));
inputPanel.add(address);
inputPanel.add(new JLabel("Phone", JLabel.CENTER));
inputPanel.add(phone);
inputPanel.add(new JLabel("Sex", JLabel.CENTER));
inputPanel.add(sex);
inputPanel.add(new JLabel("Date Of Birth", JLabel.CENTER));
inputPanel.add(dob);
inputPanel.add(new JLabel("Customer Photo ", JLabel.CENTER));
inputPanel.add(photo);
inputPanel.add(new JLabel("Voice ", JLabel.CENTER));
inputPanel.add(audio);
customerPanel.add(inputPanel, BorderLayout.NORTH);
//The buttons section:
backPanel = new JPanel();
middlePanel = new JPanel(new BorderLayout());
buttonPanel1 = new JPanel();
buttonPanel2 = new JPanel();
search = new JButton("SEARCH");
update = new JButton("UPDATE");
clear = new JButton("CLEAR");
add = new JButton("ADD");
delete = new JButton("DELETE");
close = new JButton("EXIT");
audio1 =new JButton("Voice");
//faceBrowse = new JButton("...");
//voiceBrowse =new JButton("...");
search.setPreferredSize(new Dimension(102, 26));
update.setPreferredSize(new Dimension(102, 26));
clear.setPreferredSize(new Dimension(102, 26));
add.setPreferredSize(new Dimension(102, 26));
delete.setPreferredSize(new Dimension(102, 26));
close.setPreferredSize(new Dimension(102, 26));
audio1.setPreferredSize(new Dimension(102, 26));
faceBrowse.setPreferredSize(new Dimension(26, 26));
//voiceBrowse.setPreferredSize(new Dimension(26, 26));
search.addActionListener(this);
update.addActionListener(this);
clear.addActionListener(this);
add.addActionListener(this);
delete.addActionListener(this);
close.addActionListener(this);
audio1.addActionListener(this);
//faceBrowse.addActionListener(this);
//voiceBrowse.addActionListener(this);
buttonPanel1.add(search);
//buttonPanel1.add(faceBrowse);
buttonPanel1.add(update);
buttonPanel1.add(clear);
buttonPanel2.add(add);
buttonPanel2.add(delete);
buttonPanel2.add(close);
buttonPanel2.add(audio1);
//buttonPanel1.add(voiceBrowse);
middlePanel.add(buttonPanel1, BorderLayout.NORTH);
middlePanel.add(buttonPanel2, BorderLayout.CENTER);
photoHolder = new JPanel();
Icon curPhoto = new ImageIcon("");
Icon[] custPhotos = {curPhoto};
JList photosList = new JList(custPhotos);
photosList.setFixedCellHeight(100);
photosList.setFixedCellWidth(80);
photoHolder.add(photosList);
makeComments();
backPanel.add(middlePanel);
backPanel.add(photoHolder);
backPanel.add(comments);
customerPanel.add(backPanel, BorderLayout.CENTER);
pack();
setVisible(true);
setSize(500,700);
} //makeGUI
void updateTable()
ResultSet results = null;
ResultSet results1 = null;
try
//Get the number of rows in the table so we know how big to make the data array..
int rowNumbers = 0;
int columnCount = 6;
results = stat.executeQuery("SELECT COUNT(*) FROM CUSTOMER ");
if(results.next())
rowNumbers = results.getInt(1);
} //if
if(rowNumbers == 0)
rowNumbers = 1;
tableData = new String[rowNumbers][columnCount];
//Initialize the data array with "" so we avoid possibly having nulls in it later..
for(int i =0;i<tableData.length;i++)
for(int j=0;j<tableData[0].length;j++)
tableData[i][j] = "";
//Populate the data array with results of the query on the database..
int currentRow = 0;
results1 = stat.executeQuery("SELECT * FROM CUSTOMER ORDER BY ID");
while (results1.next())
for(int i = 0; i < columnCount; i++)
tableData[currentRow] = results1.getString(i + 1);
currentRow++;
} //while
//Create the table model:
final String[] colName = { "CPR", "Name", "Address", "Phone", "Sex", "Date OF Birth" };
TableModel pageModel = new AbstractTableModel()
public int getColumnCount()
return tableData[0].length;
} //getColumnCount
public int getRowCount()
return tableData.length;
} //getRowCount
public Object getValueAt(int row, int col)
return tableData[row][col];
} //getValueAt
public String getColumnName(int column)
return colName[column];
} //getcolName
public Class getColumnClass(int col)
return getValueAt(0, col).getClass();
} //getColumnClass
public boolean isCellEditable(int row, int col)
return false;
} //isCellEditable
public void setValueAt(String aValue, int row, int column)
tableData[row][column] = aValue;
} //setValueAt
//dataTable.setValue( new JScrollBar(JScrollBar.HORIZONTAL), 2,1 );
}; //pageModel
//Create the JTable from the table model:
JTable dataTable = new JTable(pageModel);
// dataTable.setModel();
/*if (scrollpane != null)
scrollpane.setVisible(false);
scrollpane = null;
} //if*/
//scrollpane = new JScrollPane(dataTable);
//scrollpane.setVisible(true);
if (inputPanel == null)
makeGUI();
JScrollPane scrollpane =new JScrollPane(dataTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// Create vertical box for second tab
Box box = Box.createVerticalBox();
// Create component for top
box.add(customerPanel);
// Place glue between components
box.add(Box.createVerticalGlue());
// Create component for middle
box.add(middlePanel);
// Place glue between components
box.add(Box.createVerticalGlue());
// Create component for middle
box.add(backPanel);
// Place glue between components
box.add(Box.createVerticalGlue());
// Create component for bottom
box.add(scrollpane);
// Add box to JTabbedPane
tabs.add(box, "Customer");
setResizable(false);
id.grabFocus();
pack();
repaint();
adupdateTable();
} //try
catch (Exception e)
System.out.println("Caught updateTable exception: " + e);
e.printStackTrace();
} //catch
} //updatetable
//===================================================================================================
//===================================================================================================
//Update the customer table from the database:
void updateTable(String userStatus)
this.userStatus = userStatus;
updateTable();
if(userStatus.equals("user"))
delete.setEnabled(false);
tabs.setEnabledAt(1, false);
public void actionPerformed(ActionEvent e)
FileInputStream fis = null;
if (e.getSource() == add) //The ADD button.
//User has not populated all the input fields.
if(name.getText().equals("")|| address.getText().equals("")|| phone.getText().equals("")|| sex.getText().equals("")|| dob.getText().equals("")|| photo.getText().equals(""))
JOptionPane.showMessageDialog(null, "Please fill in all the fields","Missing Fields",JOptionPane.INFORMATION_MESSAGE);
else
// save the new customer:
try
//1. take the customer's data and photo:
int userId = Integer.parseInt(id.getText());
String userName = name.getText();
String userAddress = address.getText();
String userPhone = phone.getText();
String userSex = sex.getText();
String userDateBirth = dob.getText();
String photoName = photo.getText();
String audioName= audio.getText();
File file = new File(photoName);
int fileLength = (int)file.length();
//2. Set the user's photo into the photoHolder:
photoHolder.setVisible(false);
photoHolder = null;
comments.setVisible(false);
comments = null;
Icon[] custPhotos = {new ImageIcon(photoName)};
JList photosList = new JList(custPhotos);
photosList.setFixedCellHeight(100);
photosList.setFixedCellWidth(80);
photoHolder = new JPanel();
photoHolder.add(photosList);
makeComments();
//3. Insert the data and photo into the database:
if(fileLength > 0)
fis = new FileInputStream(file);
String query = " INSERT INTO CUSTOMER VALUES('"+userId+"', '"+ userName+ "', '"+ userAddress+ "', " +" '"+ userPhone+ "', '"+ userSex+ "', '"+ userDateBirth+ "', ?,?,? ) ";
PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setBinaryStream(1, fis, fileLength);
pstmt.setString(2,photoName);
pstmt.setString(3,audioName);
pstmt.executeUpdate();
comments.setText(userName+", added.");
else
String query = " INSERT INTO CUSTOMER (id, name, address, phone, sex, dob) VALUES('"+userId+"', '"+userName+"', '"+userAddress+"', '"+userPhone+"', '"+userSex+"', '"+userDateBirth+"') ";
stat.executeUpdate(query);
comments.setText("Customer saved without a photo.");
backPanel.add(photoHolder);
backPanel.add(comments);
//updateTable();
AddScroll();
} //try
catch (Exception ee)
//The danger of putting creating the JOptionPane in here is that it will show the same message regardless of the error.
JOptionPane.showMessageDialog(null, "Customers CPR already exits!!Please enter another CPR","Invalid",JOptionPane.INFORMATION_MESSAGE);
System.out.println("Caught exception in add action: " + ee);
} //catch
} //if
}//add button
void AddScroll()
JScrollPane scrollpane =new JScrollPane(dataTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.getViewport().add(dataTable);hi i tryed the JTable.revalidate() but i still did't work...
i did this :
public void actionPerformed(ActionEvent e)
FileInputStream fis = null;
if (e.getSource() == add) //The ADD button.
//User has not populated all the input fields.
if(name.getText().equals("")|| address.getText().equals("")|| phone.getText().equals("")|| sex.getText().equals("")|| dob.getText().equals("")|| photo.getText().equals(""))
JOptionPane.showMessageDialog(null, "Please fill in all the fields","Missing Fields",JOptionPane.INFORMATION_MESSAGE);
else
// save the new customer:
try
//1. take the customer's data and photo:
int userId = Integer.parseInt(id.getText());
String userName = name.getText();
String userAddress = address.getText();
String userPhone = phone.getText();
String userSex = sex.getText();
String userDateBirth = dob.getText();
String photoName = photo.getText();
String audioName= audio.getText();
File file = new File(photoName);
int fileLength = (int)file.length();
//2. Set the user's photo into the photoHolder:
photoHolder.setVisible(false);
photoHolder = null;
comments.setVisible(false);
comments = null;
Icon[] custPhotos = {new ImageIcon(photoName)};
JList photosList = new JList(custPhotos);
photosList.setFixedCellHeight(100);
photosList.setFixedCellWidth(80);
photoHolder = new JPanel();
photoHolder.add(photosList);
makeComments();
//3. Insert the data and photo into the database:
if(fileLength > 0)
fis = new FileInputStream(file);
String query = " INSERT INTO CUSTOMER VALUES('"+userId+"', '"+ userName+ "', '"+ userAddress+ "', " +" '"+ userPhone+ "', '"+ userSex+ "', '"+ userDateBirth+ "', ?,?,? ) ";
PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setBinaryStream(1, fis, fileLength);
pstmt.setString(2,photoName);
pstmt.setString(3,audioName);
pstmt.executeUpdate();
comments.setText(userName+", added.");
else
String query = " INSERT INTO CUSTOMER (id, name, address, phone, sex, dob) VALUES('"+userId+"', '"+userName+"', '"+userAddress+"', '"+userPhone+"', '"+userSex+"', '"+userDateBirth+"') ";
stat.executeUpdate(query);
comments.setText("Customer saved without a photo.");
backPanel.add(photoHolder);
backPanel.add(comments);
//updateTable();
dataTable.revalidate();
AddScroll();
} //try
catch (Exception ee)
//The danger of putting creating the JOptionPane in here is that it will show the same message regardless of the error.
JOptionPane.showMessageDialog(null, "Customers CPR already exits!!Please enter another CPR","Invalid",JOptionPane.INFORMATION_MESSAGE);
System.out.println("Caught exception in add action: " + ee);
ee.printStackTrace();
} //catch
} //if
}//add buttonand i included this function AddScroll() that i will add the scroll bars :
void AddScroll()
JScrollPane scrollpane =new JScrollPane(dataTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.getViewport().add(dataTable);
// AbstractTableModel pageModel = (AbstractTableModel)dataTable.getModel();
// pageModel .fireTableDataChanged();
//dataTable.updateUI();
}thankx -
Browser scrollbar and Flash scrollbar ? I need help!
Now I have a problem about the scrollbar:
The height of my swf file is longer than browser height, so
the scrollbar of browser's occurred, if I scroll my mouse wheel,
the whole flash roll down, but the problem is that I have used a
scrollPanel component which write by myself, and in this situation,
when I scroll the mouse wheel, the scrollbar in flash and browser
will both in effect.
The question is that how to disable the brower scrollbar when
I scroll mouse wheel inside the scrollPanel component. In fact,
adobe already done this, if my cursor inside a textfield object,
the scrollbar of bowser will not get focus. How to achieve this
effect? My english is bad, but I need help!i recently downloaded trails of flash cs4 and web premium package cs4 (took a day to download at high speed starbuck's internet). couldnt get the setup.exe to work or the uninstaller to work. surfing tech support over next couple weeks to try various agents was useless and expensive until i finally reached someone with useful info. all the agents had foriegn accents and read from scripts and web support pages until yesterday, when i reached a guy who told me two things i'll report to various forums addressing this same issue:
1. download windows uninstaller program from their website (google: windows ininstaller). this program is different from the one that doesnt work in the programs and features area of control panel when you try to uninstall adobe products from there.
2. windows explorer 8, the newest version, DOES NOT download adobe softare properly and leaves things out, causing all sorts of issues including the setup.exe program not working. download firefox browser from mozella (google: firefox) and use it for all adobe downloads. apparently the old windows explorer 7 will work, but if you already have explorer 8 installed its easiest to just use firefox.
i'm spending the next couple days downloading the 4.14 G web premium trail with firefox and will report if this works. -
Need some help disabling/enabling the scrollbar on our website
Dear Sir/madam,
I am having some difficulty with our website to disable or hide the scrollbar on our website.
The thing is that i want to disable/hide the scrollbar when i got a small web page with only one alinea of text.
And i want to enable the scrollbar when i got more then one alinea of text and my webpage is a lot bigger.
Can anyone help me out?
Here is my CSS code file and html file
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Trend installatietechniek BV - Home</title>
<meta name="Keywords" content="domotica, schakelaar, rookmelder, elektrische apparatuur">
<meta name="Description" content="Domotica is een verzamelwoord voor het aan elkaar koppelen van verschillende systemen, zoals rookmelder, video-intercom en rookmelder.">
<meta name="robots" content="index, follow">
<meta name="revisit-after" content="1 month">
<meta name="googlebot" content="noodp">
<meta name="language" content="dutch, nederland, netherlands, nl">
<meta name="author" content="trenbv.nl, Trend Installatietechniek BV">
<style type="text/css">
</style>
<link href="trendbv2.css" rel="stylesheet" type="text/css" />
<style type="text/css">
a:visited {
color: #666666;
</style>
<script type="text/javascript">
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
</script>
</head>
<body onload="MM_preloadImages('Beelden/hoofdnavigatieData.png','Beelden/hoofdnavigatieElektrot echniek.png','Beelden/hoofdnavigatieBeveiliging.png','Beelden/hoofdnavigatieTechnischBeh.p ng')">
<div id="achtergrondmidden"><img src="Beelden/achtergrond.png" alt="achtergrondTrendbv" width="1024" height="751" border="0" /></div>
<div id="fotogrootmidden"><img src="Beelden/Groot Home.jpg" width="944" height="360" alt="domoticaTrendbv" /></div>
<div id="balkmidden"></div>
<div id="logoTrendonder"></div>
<div class="broodtekst" id="contactgegevens">
<strong>Trend Installatietechniek BV</strong><br />
<br />
Kazemat 33<br />
3905 NR Veenendaal
<p><strong>E:</strong> <a href="[email protected]:[email protected]">[email protected]</a><br />
<strong>T:</strong> (0318) 51 63 02</p>
</div>
<div class="broodtekst" id="subnavigatie"></div>
<div class="navigatiebovenaan" id="navigatiebovenaan">home <a href="Tekenwerk.html">tekenwerk</a> <a href="klanten.html">klanten</a> <a href="ons bedrijf.html">ons bedrijf</a> <a href="contact.html"> contact</a></div>
<div class="broodtekst" id="tekstkolom">
<p>Trend Installatietechniek is een specialist op het gebied van elektrotechniek en bestaat sinds 1998. Inmiddels is Trend uitgegroeid tot een gerenommeerd elektrotechnisch bedrijf met vestigingen in Veenendaal en Assen.<br />
<br />
Trend Installatietechniek heeft sinds jaar en dag een reputatie op het gebied van aanleg van datanetwerken en elektrotechnische installaties.<br />
U verwacht van een elektrotechnisch installateur vakmanschap en kwaliteit. Naast kwalitatief hoogstaand werk onderscheiden wij ons door een klantgerichte houding en korte levertijden. <br />
<br />
Wij voeren opdrachten uit voor klanten zoals het ZIGGO, KNAW, de Universiteit van Amsterdam en KPN. Hierbij wordt veel verwacht van onze monteurs. Daarom werken wij uitsluitend met ervaren, gediplomeerde elektrotechnische monteurs. <br />
</p>
</div>
<div id="tekstfoto1"><img src="Beelden/beeldhome2.png" alt="fotodomotica1" width="130" height="130" border="0" /></div>
<div id="tekstfoto2"></div>
<div id="hoofdnavigatieDomotica"><a href="Wat is domotica.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','Beelden/hoofdnavigatieDomotica.png',1)"><img src="Beelden/hoofdnavigatieDomotica-kort.png" alt="Hoofdnavigatie Domotica" name="Image5" width="583" height="65" border="0" id="Image5" /></a></div>
<div id="hoofdnavigatieData"><a href="Wat is Data.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','Beelden/hoofdnavigatieData.png',1)"><img src="Beelden/hoofdnavigatieData-kort.png" alt="Hoofdnavigatie Data" name="Image6" width="472" height="65" border="0" id="Image6" /></a></div>
<div id="hoofdnavigatieElektrotechniek"><a href="Wat is Elektrotechniek.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image7','','Beelden/hoofdnavigatieElektrotechniek.png',1)"><im g src="Beelden/hoofdnavigatieElektrotechniek-kort.png" alt="Hoofdnavigatie Elektrotechniek" name="Image7" width="356" height="65" border="0" id="Image7" /></a></div>
<div id="hoofdnavigatieBeveiliging"><a href="Beveiliging en camerasystemen.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image8','','Beelden/hoofdnavigatieBeveiliging.png',1)"><img src="Beelden/hoofdnavigatieBeveiliging-kort.png" alt="Hoofdnavigatie Beveiliging" name="Image8" width="245" height="65" border="0" id="Image8" /></a></div>
<div id="hoofdnavigatieTechnischBeheer"><a href="Technisch beheer.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image9','','Beelden/hoofdnavigatieTechnischBeh.png',1)"><img src="Beelden/hoofdnavigatieTechnischBeh-kort.png" alt="Hoofdnavigatie Technisch Beheer" name="Image9" width="134" height="65" border="0" id="Image9" /></a></div>
<div id="body"></div>
<div id="kaderlinks"></div>
<div id="kaderrechts"></div>
<div id="hoofdnavigatie"></div>
<div id="achtergrondvertikaal"></div>
</body>
</html>
CSS file:
@charset "UTF-8";
#body {
position: fixed;
width: 100%;
z-index: 1;
left: 0px;
top: 0px;
background-image: url(Beelden/achtergrondbody.png);
height: 100%;
background-repeat: repeat-y
#kaderlinks {
position: fixed;
left: 50%;
top: 0px;
width: 5px;
height: 100%;
z-index: 21;
background-image: url(Beelden/kader.png);
background-repeat: repeat-y;
margin-left: -512px;
#fotogrootmidden {
position:absolute;
left:50%;
top:52px;
width:944px;
height:360px;
z-index:2;
margin-left: -472px;
#achtergrondmidden {
position: absolute;
left: 50%;
top: 0px;
width: 1024px;
height: 751px;
z-index: 3;
margin-left: -512px;
#balkmidden {
position: absolute;
left: 50%;
top: 378px;
width: 642px;
height: 49px;
z-index: 3;
margin-left: -130px;
background-image: url(Beelden/blauwebalk.png);
background-position: left;
#achtergrondvertikaal {
position: absolute;
left: 50%;
top: 751px;
width: 1024px;
height: 100%;
z-index: 4;
margin-left: -512px;
background-image: url(Beelden/achtergrondonder.png);
#logoTrendonder {
position: fixed;
left: 50%;
height: 100%;
z-index: 5;
background-image: url(Beelden/logotrendonder.png);
background-repeat: no-repeat;
margin-left: -439px;
background-position: bottom;
width: 179px;
#contactgegevens {
position:fixed;
left:50%;
width:130px;
z-index:10;
margin-left: -410px;
color: #000;
vertical-align: bottom;
top: 100%;
margin-top: -260px;
#contactgegevens p strong {
color: #2B79BE;
#navigatiebovenaan {
position:absolute;
left:50%;
top:25px;
width:404px;
height:23px;
z-index:12;
text-align: right;
margin-left: 50px;
#navigatiebovenaan a:link {
color: #999;
#navigatiebovenaan a:hover {
color: #2B79BE;
#hoofdnavigatieDomotica {
position:absolute;
left:50%;
top:58px;
width:596px;
height:82px;
z-index:16;
margin-left: -118px;
#hoofdnavigatieData {
position:absolute;
left:50%;
top:58px;
width:467px;
height:82px;
z-index:17;
margin-left: -3px;
clip: rect(auto,auto,auto,0px);
#hoofdnavigatieElektrotechniek {
position:absolute;
left:50%;
top:58px;
width:363px;
height:82px;
z-index:18;
margin-left: 110px;
#hoofdnavigatieBeveiliging {
position:absolute;
left:50%;
top:58px;
width:254px;
height:82px;
z-index:19;
margin-left: 220px;
#hoofdnavigatieTechnischBeheer {
position:absolute;
left:50%;
top:58px;
width:139px;
height:84px;
z-index:20;
margin-left: 330px;
#subnavigatie {
position: absolute;
left: 50%;
top: 393px;
width: 581px;
height: 19px;
z-index: 11;
margin-left: -103px;
#tekstkolom {
position: absolute;
left: 50%;
top: 458px;
width: 400px;
height: 345px;
z-index: 13;
margin-left: 50px;
text-align: left;
font-size: 12px;
#tekstfoto1 {
position: absolute;
left: 50%;
top: 470px;
width: 150px;
height: 380px;
z-index: 14;
margin-left: -116px;
#tekstfoto2 {
position: absolute;
left: 556px;
top: 620px;
width: 130;
height: 130;
z-index: 15;
margin-left: -116px;
#kaderrechts {
position: fixed;
left: 50%;
top: 0px;
width: 5px;
height: 100%;
z-index: 22;
background-image: url(Beelden/kader.png);
background-repeat: repeat-y;
margin-left: 512px;
.navigatiebovenaan {
font-family: Arial, Helvetica, sans-serif;
color: #999;
font-size: 12px;
.broodtekst {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 16px;
a:link {
text-decoration: none;
color: #000;
a:hover {
color: #2B79BE;
text-decoration: none;
.h1 {
font-family: Arial, Helvetica, sans-serif;
color: #2B79BE;
font-size: 17px;
font-weight: lighter;Start by remvoing the code in RED.
#body {
position: fixed;
width: 100%;
z-index: 1;
left: 0px;
top: 0px;
background-image: url(Beelden/achtergrondbody.png);
height: 100%;
background-repeat: repeat-y
Browser scrollbars appear by default in all pages requiring them. You don't need to do anything to make them appear. I don't think you understand Fixed positioning well enough to be using it so much in your CSS. It has a purpose but probably not what you think.
See position:fixed sticky text demo.
http://alt-web.com/DEMOS/CSS2-Sticky-Text.shtml
Nancy O. -
Need help creating horizontal scrollbar in graphic timelime (built in AI)!
I am trying to use Catlyst to build an interactive scrollbar on a graphic timeline build in Adobe Illustrator, I want to be able to scroll from one end of timeline to the other. Can anyone help? Thanks!
Can you post a screenshot of the timeline you are trying to convert. It will help in accurate response.
You would probably need to do it in two step:
- Have the graphic timeline converted into Datalist element, and make the data repeatable.
- Create a Horizontal Scrollbar component and add it to the datalist component (timeilne)
- If you have the Horizontal scrollbar designed, then select it and convert it to a Horizontal Scroll component (using the HUD - the black overlay that comes up when you select a graphic element)
- After conversion you would need to define the parts of the H. Scrollbar (Track, thumb, right button, left button). Note: It helps if you designed your H. Scrollbar with these components in AI/PSD.
- Now come back to the artboard, and select the H. Scrollbar by clicking on it.
- Cut the H. Scrollbar
- Click the Datalist element, and go to Edit Parts (in HUD)
- Paste the H . Scrollbar inside the Datalist element. This will attach the scrollbar to the data.
Hope this helps,
Fu -
Tutor 14.0 Problem - Please help! Vertical scrollbar missing
I recently upgraded from Tutor 12.2 to Tutor 14.0.
When I publish the Desk Manuals for each actor, the html page does not have the vertical scrollbar, and you can't access the documents that are at the bottom of the list.
Has anyone experienced this? Is there a fix for this? I searched for patches in Oracle Support but could not locate any.
I tried to troubleshoot this by replacing the tutor.css files and tutor_script.js file with those from 12.2, but that didn't work. Is there another file that controls the output of HTML files when you publish through Tutor Publisher?
Please help!
Thanks!Ok i am sorry about giving the wall paper here is to more precise problem
and
if you could possibly tell me a simple way of Importing a .gif file and drawing in Java.
if(rect == true)
if(cex>=origx&&cey>=origy)
drx[rc] = cx;
dry[rc] = cy;
urx[rc] = cex-cx;
ury[rc] = cey-cy;
rc++;
trc++;
else if(cex>=origx&&cey<origy)
drx[rc] = cx;
dry[rc] = cey;
urx[rc] = cex-cx;
ury[rc] = cy-cey;
rc++;
trc++;
else if(cex<origx&&cey<origy)
drx[rc] = cex;
dry[rc] = cey;
urx[rc] = cx-cex;
ury[rc] = cy-cey;
rc++;
trc++;
else if(cex<origx&&cey>origy)
drx[rc] = cex;
dry[rc] = cy;
urx[rc] = cx-cex;
ury[rc] = cey-cy;
rc++;
trc++;
}Thx -
Scrollbar in Panel.....help
hi.... i have to add images(picture) in Panel .because I have to add more pictures(image), scrollbar (or JScrollPane) will require please help me how to do.
U can also help in respect of following program, Thanks.
// <applet code="AnImageApplet" width="400" height="400"></applet>
// use: >appletviewer AnImageApplet.java
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
public class AnImageApplet extends Applet
public void init()
setLayout(new BorderLayout());
add(new AnImagePanel());
public static void main( String[] args )
Applet applet = new AnImageApplet();
Frame frame = new Frame( "Image" );
frame.addWindowListener(closer);
frame.add(applet);
frame.setSize(400,400);
frame.setLocation(200,200);
applet.init();
frame.setVisible(true);
private static WindowListener closer = new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
class AnImagePanel extends Panel
BufferedImage image;
public AnImagePanel()
try
image = ImageIO.read(//"yu.jpg");
new File("images/cougar.jpg"));
catch(IOException e)
System.out.println("Read error: " + e.getMessage());
public void paint(Graphics g) {
g.drawImage(image, 20, 20, this);
}// <applet code="AnImageApplet" width="400" height="400"></applet>
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
public class AnImageApplet extends Applet {
public void init() {
setLayout(new BorderLayout());
ScrollPane scrollPane = new ScrollPane();
scrollPane.add(getContent());
add(scrollPane);
private Panel getContent() {
Panel panel = new Panel(new GridLayout(0,2,5,5));
panel.add(new AnImagePanel("images/cougar.jpg"));
panel.add(new AnImagePanel("images/bclynx.jpg"));
panel.add(new AnImagePanel("images/redfox.jpg"));
panel.add(new AnImagePanel("images/mtngoat.jpg"));
return panel;
public static void main( String[] args ) {
Applet applet = new AnImageApplet();
Frame frame = new Frame( "Image" );
frame.addWindowListener(closer);
frame.add(applet);
frame.setSize(400,400);
frame.setLocation(200,200);
applet.init();
frame.setVisible(true);
private static WindowListener closer = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
class AnImagePanel extends Panel {
BufferedImage image;
public AnImagePanel(String path) {
try {
image = ImageIO.read(new File(path));
} catch(IOException e) {
System.out.println("Read error: " + e.getMessage());
public void paint(Graphics g) {
int x = (getWidth() - image.getWidth())/2;
int y = (getHeight() - image.getHeight())/2;
g.drawImage(image, x, y, this);
public Dimension getPreferredSize() {
return new Dimension(image.getWidth(), image.getHeight());
}
Maybe you are looking for
-
How to get the current Mailbox size
Hi, Does anyone know how to get the current size of Mailbox and Archive by using GW api?
-
I'm trying to set SName to the username, then get the volumes restrictions based on the variable SName, which is set to the username. How do you use variables in NScript functions? here is the statement taht errors: Set restr = RestrictionsObj.Elemen
-
WVC210 problem after FW update
Hi After trying to upgrade the FW on my WVC210 to 1.1.1.15 the unit will no longer power up correctly. The camera PTZ mechanism still sweeps left/right and up/down at power up, but that is all. The 4 panel LEDs stay illuminated continually. I have tr
-
Using workspaces with large tables
Hello I've got a few large tables (6-10GB+) that will have around 500k new rows added on a daily basis as part of an overnight batch job. No rows are ever updated, only inserted or deleted and then re-inserted. I want to stop the process that adds th
-
HT204406 turned off iMatch under Store in iTunes now can't turn back on?
turned off iMatch under Store in iTunes and now can't turn back on - any ideas