修飾子
public class ScrollPane
父類別
public class Container
實作介面
ImageObserver
MenuContainer
Serializable
Accessible
建構子
ScrollPane()
ScrollPane(int scrollbarDisplayPolicy)
常用屬性
名稱 敘述 SCROLLBARS_ALWAYS 整數常數 1 ,用為一直出現捲軸 SCROLLBARS_AS_NEEDED 整數常數 0 ,用為需要時出現捲軸 SCROLLBARS_NEVER 整數常數 2 ,用為不會出現捲軸
舉例如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import java.awt.*; import java.awt.event.*; public class ScrollpaneDemo2 { public static void main(String[] args) { Frame frame = new Frame( "AWTDemo" ); frame.addWindowListener( new AdapterDemo()); frame.setSize( 100 , 100 ); Button button1 = new Button( "b1" ); button1.setSize( 32 , 20 ); Button button2 = new Button( "b2" ); button2.setSize( 32 , 20 ); Button button3 = new Button( "b3" ); button3.setSize( 32 , 20 ); Button button4 = new Button( "b4" ); button4.setSize( 32 , 20 ); Panel panel = new Panel( new FlowLayout()); panel.add(button1); panel.add(button2); panel.add(button3); panel.add(button4); ScrollPane scrollpane = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS); scrollpane.add(panel); frame.add(scrollpane); frame.setVisible( true ); } } class AdapterDemo extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit( 0 ); } } /* 《程式語言教學誌》的範例程式 檔名:ScrollpaneDemo2.java 功能:示範 Java 程式 作者:張凱慶 時間:西元 2012 年 3 月 */ |
此例的 ScrollpaneDemo2 類別先建立四個 Button 按鈕,然後建立一個 Panel ,把四個按鈕放在 Panel 中
10 11 12 13 14 15 16 17 18 19 20 21 22 | Button button1 = new Button( "b1" ); button1.setSize( 32 , 20 ); Button button2 = new Button( "b2" ); button2.setSize( 32 , 20 ); Button button3 = new Button( "b3" ); button3.setSize( 32 , 20 ); Button button4 = new Button( "b4" ); button4.setSize( 32 , 20 ); Panel panel = new Panel( new FlowLayout()); panel.add(button1); panel.add(button2); panel.add(button3); panel.add(button4); |
接著建立 ScrollPane 物件,並以 ScrollPane 的 SCROLLBARS_ALWAYS 屬性當參數
24 25 | ScrollPane scrollpane = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS); scrollpane.add(panel); |
編譯後執行,結果如下

中英文術語對照 | |
---|---|
類別 | class |
建構子 | constructor |
方法 | method |
您可以繼續參考
AWT 元件
相關目錄
Java API 分類導覽
Java 教材
首頁
參考資料
http://docs.oracle.com/javase/6/docs/api/java/awt/ScrollPane.html
沒有留言:
張貼留言