我有一个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类关于你想要什么?我不太明白。 –