我有一個Java應用程序,我想將按鈕格式化爲Active或Inactive(也可能是懸停方法)。向JButton類添加自定義方法
,因爲我想實現它的代碼:
//Home Tab - Active by default
home = new TabButton();
home.setSize(new Dimension(tabWidth, tabHeight));
home.setFont(getLauncherFont(34));
home.setForeground(Color.white);
home.setText("HOME");
home.setBounds(160, 0, tabWidth, tabHeight);
home.setActive(); --> This Method is what I would like to create
我已經有一個類來創建一個JButton的標籤:
package com.anarcist.minemodloaderv1.skin.components;
import java.awt.Color;
import javax.swing.JButton;
/**
*
* @author anarcist
*/
public class TabButton extends JButton {
public TabButton() {
this.setBorderPainted(false);
this.setFocusPainted(false);
this.setContentAreaFilled(true);
this.setBackground(Color.blue);
}
}
我研究的抽象類。但是我的TabButton類已經擴展了JButton。
我想這樣的方法:
public void setActive(){
this.setBackground(Color.red);
//Any other changes a want to make regularly
}
,可以簡單地這樣home.setActive();
我的問題,我想實現的是:它是很容易的實現我所期待的,或我是否必須每次都手動設置所有屬性?
我不知道是什麼ü意味着,但你可以用U希望 – Zion
請你更加精確的每一個方法延長您TabButton類關於你想要什麼?我不太明白。 –