Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/04/2019, 21:08
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años
Puntos: 6
Respuesta: Personalizando JList

Continuo poniendo el código:

Código Java:
Ver original
  1. package app.vista.util.columnas;
  2. import java.awt.FlowLayout;
  3. import javax.swing.BorderFactory;
  4. import javax.swing.JLabel;
  5. import javax.swing.JPanel;
  6. public class HeaderPanel extends JPanel {
  7.     public HeaderPanel() {            
  8.         setLayout(new FlowLayout(FlowLayout.LEFT, 2, 2));
  9.     }
  10.     protected void customeHeader(JLabel xheader,int lr){
  11.         xheader.setHorizontalTextPosition(JLabel.LEFT);
  12.         xheader.setVerticalTextPosition(JLabel.BOTTOM);
  13.         xheader.setBorder(BorderFactory.createEmptyBorder(5, lr, 5, lr));
  14.     }
  15. }

Código Java:
Ver original
  1. package app.vista.util.columnas;
  2. import javax.swing.JLabel;
  3. public class HeaderRegistro extends HeaderPanel {
  4.     private JLabel lregistro = new JLabel("Registro");
  5.     private JLabel lfecha = new JLabel("Fecha");
  6.     private JLabel lpaciente = new JLabel("Paciente");
  7.     private JLabel lmedico = new JLabel("Médico");
  8.     private JLabel ldescripcion = new JLabel("Descripción");
  9.     private JLabel ltratamiento = new JLabel("Tratamiento");
  10.     public HeaderRegistro() {
  11.         super();
  12.         this.customeHeader(lregistro, 30);
  13.         this.customeHeader(lfecha, 60);
  14.         this.customeHeader(lpaciente,70);
  15.         this.customeHeader(lmedico,70);
  16.         this.customeHeader(ldescripcion,120);
  17.         this.customeHeader(ltratamiento,120);        
  18.         this.add(lregistro);
  19.         this.add(lfecha);
  20.         this.add(lpaciente);
  21.         this.add(lmedico);
  22.         this.add(ldescripcion);
  23.         this.add(ltratamiento);
  24.     }
  25.     public JLabel getLregistro() {
  26.         return lregistro;
  27.     }
  28.     public JLabel getLfecha() {
  29.         return lfecha;
  30.     }
  31.     public JLabel getLpaciente() {
  32.         return lpaciente;
  33.     }
  34.     public JLabel getLmedico() {
  35.         return lmedico;
  36.     }
  37.     public JLabel getLdescripcion() {
  38.         return ldescripcion;
  39.     }
  40.     public JLabel getLtratamiento() {
  41.         return ltratamiento;
  42.     }    
  43. }

Para cargar en el formulario:

Código Java:
Ver original
  1. private void cargarHistoriaClinica(Paciente paciente){
  2.         pnlshowhistoriaclinica.removeAll();
  3.         pnlshowhistoriaclinica.setLayout(new BorderLayout());
  4.         HeaderRegistro hreg = new HeaderRegistro();                
  5.         lthistoriaclinica.setModel(new ModeloRegistro(paciente));
  6.         lthistoriaclinica.setCellRenderer(new CeldaRegistro(hreg));
  7.         sphistoriaclinica = new JScrollPane(lthistoriaclinica);
  8.         pnlshowhistoriaclinica.add(hreg, BorderLayout.PAGE_START);
  9.         pnlshowhistoriaclinica.add(sphistoriaclinica);
  10.         pnlshowhistoriaclinica.updateUI();
  11.     }

Pongo un link que tiene una imagen para que ven mejor el problema:

Tratando de personalizar los JList

Espero sus respuestas y saludos.
__________________
Si te interesa, visita mi perfil de Linkedin. Gracias