Good afternoon. My question is how to generate several properties for a component (for example a JLabel) and be able to assign it to all the JLabel instants.
Whenever we installed a JLabel we made the following steps.
JLabel ejemploLb = new JLabel();
ejemploLb.setText("LISTADO DE MIEMBROS");
ejemploLb.setFont(new Font("Arial", 1, 18));
ejemploLb.setBackground(Color.red);
And so on every time we start a JLabel, with this I want to ask, is there the possibility of being able to take the properties of that component (JLabel) and apply it to another JLabel without having to write the same lines again?
An idea has occurred to me but I would like to find another one simpler. This is my example.
/*Instanciamos los componentes*/
titleLb = new JLabel("LISTADO DE CLIENTES");
titleL2b = new JLabel("LISTADO DE PROVEEDORES");
/*Llamamos al método y mandamos el JLabel*/
initJLabel(titleLb);
initJLabel(titleLb2);
/*En el método introducimos las propiedades que queremos para los JLabel*/
private void initJLabel(JLabel label){
label.setFont(new Font("Arial", 1, 18));
label.setBackground(Color.red);
}
Do you know a simpler way? Thank you very much for everything.