I have a JDateChooser
and would like to change the background when it won focu
, however I'm not getting it.
I tried to do it in some ways:
dataChooser.getDateEditor().getUiComponent().setBackground(new Color(0, 0, 0));
or
dataChooser.setBackground(new Color(0, 0, 0));
and this I put inside the event of focusGained
import com.toedter.calendar.JDateChooser;
import java.awt.Color;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JPanel;
public class BackGr extends JFrame {
JDateChooser data = new JDateChooser();
JPanel painel = new JPanel();
public BackGr() {
setSize(300, 150);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
painel.add(data);
data.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
data.getDateEditor().getUiComponent().setBackground(new Color(0, 0, 0));
//data.setBackground(new Color(0, 0, 0));
}
@Override
public void focusLost(FocusEvent e) {
}
});
add(painel);
}
public static void main(String[] args) {
BackGr bg = new BackGr();
bg.setVisible(true);
}
}