要在 Swing 中執行背景程式, 要使用 SwingWorker 物件.
繼承 SwingWorker 物件後, 要覆寫 doInBackground(). 在 doInBackground() 中放的就是我們要執行的背景程式內容.
2011年2月7日 星期一
2011年1月30日 星期日
Swing GUI 下背景工作程式
介紹在 Swing 程式下 javax.swing.SwingWorker。當在 Swing GUI 程式中要執行長時間的工作時, 可以利用 SwingWorker 物件, 把工作放到背景執行。 另外介紹在 Application framework (JSR 296) 下的 TaskService 及 TaskMonitor.
文件下載
文件下載
2011年1月28日 星期五
Swing layout
Swing layout 會自動的調整元件的大小, 不同的 layout 調整大小時所遵照的規則有所不同, 整理如下:
BoxLayout: requested maximum sizes
FlowLayout: preferred sizes
BorderLayout: preferred sizes
GridLayout: Each component takes all the available space within its cell, and each cell is exactly the same size
GridBagLayout: preferred sizes
BoxLayout: requested maximum sizes
FlowLayout: preferred sizes
BorderLayout: preferred sizes
GridLayout: Each component takes all the available space within its cell, and each cell is exactly the same size
GridBagLayout: preferred sizes
2011年1月20日 星期四
Icon 介面中的 PaintIcon() 方法
Icon 介面中有一個抽象方法 PaintIcon(), 用來畫出 icon. 這個方法的宣告如下:
void paintIcon(Component c, Graphics g, int x, int y)
方法裡有四個參數:
x, y: 畫 icon 的位置
g: 繪圖物件
c: 用來取得繪圖所需要的屬性, 如前景或背景顏色.
2011年1月16日 星期日
Swing JTable 的使用
使用 Swing JTable 的建議驟:
1.繼承 AbstractTableModel
2. 實作以下的方法:
1.繼承 AbstractTableModel
2. 實作以下的方法:
public int getRowCount(); public int getColumnCount(); public Object getValueAt(int row, int column);
getValueAt() 的方法主要傳回儲存資料的集合中的值.
3. 若要改變 table 的 header, 要覆寫以下方法:
String
getColumnName(int column)
4. 撰寫一方法, 設定或更新儲存資料的集合. 更新完後, 記得到執行
void fireTableDataChanged()
或者其它 void fireXXX 的方法, 將資料顯示出來.
訂閱:
文章 (Atom)