forked from LupusNobilis/java-org.hwo.ui
added colored toggleButton
parent
d86830f119
commit
a5f3bc3781
|
@ -0,0 +1,76 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JToggleButton;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
public class JColoredToggleButton extends JToggleButton {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Color colorOff, colorOn;
|
||||
private boolean state = false;
|
||||
|
||||
public JColoredToggleButton(Color on, Color off) {
|
||||
this.colorOn = on;
|
||||
this.colorOff = off;
|
||||
}
|
||||
|
||||
public JColoredToggleButton(String text, Color on, Color off) {
|
||||
super(text);
|
||||
this.colorOn = on;
|
||||
this.colorOff = off;
|
||||
}
|
||||
|
||||
public JColoredToggleButton(Action a) {
|
||||
super(a);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JColoredToggleButton(Icon icon, boolean selected) {
|
||||
super(icon, selected);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JColoredToggleButton(String text, boolean selected) {
|
||||
super(text, selected);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JColoredToggleButton(String text, Icon icon) {
|
||||
super(text, icon);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JColoredToggleButton(String text, Icon icon, boolean selected) {
|
||||
super(text, icon, selected);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public void toggle(boolean tgl) {
|
||||
this.state = tgl;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
|
||||
if(state) {
|
||||
super.setBackground(colorOff);
|
||||
super.setForeground(colorOff);
|
||||
}
|
||||
else {
|
||||
super.setBackground(colorOn);
|
||||
super.setForeground(colorOn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue