2
I have a JDateChooser
and I’d like to change the background when he wins focu
, but I’m not getting it.
I tried to do some ways:
dataChooser.getDateEditor().getUiComponent().setBackground(new Color(0, 0, 0));
or
dataChooser.setBackground(new Color(0, 0, 0));
and this I put into 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);
}
}
Please add a [mcve] of your code so it is possible to test and see the problem running.
– user28595
@Articuno put there, sorry !
– Javinha
What does that mean
focu
that you highlighted?– user28595
focu , in the sense of entering with the cursor in the field, I think I wrote wrong.
– Javinha
The application already opens with this field in focus?
– user28595
in this case this, however I tested without starting directly with the focu, and the result is the same.
– Javinha