我有一个Java应用程序,我想将按钮设置为“活动”或“不活动”(也可能是一种悬停方法)。
我想实现的代码:
//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();
我想我的问题是:实现我要寻找的内容是否足够容易,还是我必须走很长的路才能每次都手动设置所有属性?
您在帖子中描述的内容可以这样完成:
package com.anarcist.minemodloaderv1.skin.components;
import java.awt.Color;
import javax.swing.JButton;
/**
*
* @author anarcist
*/
public class TabButton extends JButton {
public TabButton() {// initialize
this.setBorderPainted(false);
this.setFocusPainted(false);
this.setContentAreaFilled(true);
this.setBackground(Color.blue);
}
// add your own methods or override JButton methods
public void setActive(){
//Add code
//example: setEnabled(true);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句