java 77

Curso de Java Netbeans Completo☕ [77.- Alinear etiquetas (Alignment label)]

En este tutorial vamos a seguir manipulando nuestras etiquetas y en esta ocacion le toca Alinear etiquetas y los colores de fondo.

Java swing: https://es.wikipedia.org/wiki/Swing_(biblioteca_gr%C3%A1fica)

Codigo: https://github.com/programadornovato/java/commit/5ca21529f32ac297efd2e994bcfabb49421adcc7

package com.programadornovato.proy1;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.HeadlessException;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

/**
 *
 * @author eugenio
 */
public class Ventana extends JFrame{
        JPanel panel1;
        JPanel panel2;
        JPanel panel3;
        JLabel e1;
        JLabel e2;
        JLabel e3;
    /*
    public Ventana() throws HeadlessException {
        Dimension d=new Dimension(500, 500);
        this.setSize(d);
    }
    */
    public Ventana(String title) throws HeadlessException, InterruptedException {
        super(title);
        //Dimension d=new Dimension(500, 500);
        //this.setSize(d);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //this.setLocation(300, 300);
        this.setBounds(300, 300, 500, 500);
        this.setLocationRelativeTo(null);
        iniciarPaneles();
        inicaEtiquetas();
    }

    protected void iniciarPaneles() {
        JPanel contenedor=new JPanel();
        this.getContentPane().add(contenedor);
        contenedor.setBackground(Color.red);
        this.panel1=new JPanel();
        this.panel2=new JPanel();
        this.panel3=new JPanel();
        contenedor.add(this.panel1);
        contenedor.add(this.panel2);
        contenedor.add(this.panel3);
        this.panel1.setBackground(new Color(0, 51, 102));
        this.panel2.setBackground(new Color(0, 102, 255));
        this.panel3.setBackground(new Color(255, 0, 255));
        contenedor.setLayout(new BoxLayout(contenedor, BoxLayout.X_AXIS));
        //this.panel3.setVisible(false);
    }

    protected void inicaEtiquetas() {
        e1=new JLabel("<html>Hola1</html>");
        e2=new JLabel("<html>Hola2</html>");
        e3=new JLabel("<html>Hola3</html>");
        
        this.panel1.add(e1);
        this.panel2.add(e2);
        this.panel3.add(e3);
        
        e1.setForeground(Color.white);
        e2.setForeground(Color.white);
        e3.setForeground(Color.white);
        
        this.panel1.setLayout(null);
        this.panel2.setLayout(null);
        this.panel3.setLayout(null);
        
        e1.setBounds(10, 100, 120, 60);
        e2.setBounds(10, 100, 120, 60);
        e3.setBounds(10, 100, 120, 60);
        
        //e1.setText("<html>Hola humano</html>");
        //this.panel2.setVisible(false);
        e1.setOpaque(true);
        e2.setOpaque(true);
        e3.setOpaque(true);
        
        e1.setBackground(Color.black);
        e2.setBackground(Color.black);
        e3.setBackground(Color.black);
        /*
        HorizontalAlignment
        CENTER  = 0;
        LEFT    = 2;
        RIGHT   = 4;
        
        VerticalAlignment
        TOP     = 1;
        BOTTOM  = 3;
	*/

        e1.setHorizontalAlignment(SwingConstants.LEFT);
        e2.setHorizontalAlignment(SwingConstants.CENTER);
        e3.setHorizontalAlignment(SwingConstants.RIGHT);
        
        e1.setVerticalAlignment(SwingConstants.TOP);
        e2.setVerticalAlignment(SwingConstants.BOTTOM);
        
    }
    public void setTextos(String textos[]){
        this.e1.setText(textos[0]);
        this.e2.setText(textos[1]);
        this.e3.setText(textos[2]);
    }
    
}

🔗 Instalar Netbeans 11 en Ubuntu con Snap [Mas fácil que en windows?]: https://www.youtube.com/watch?v=LllPPV9SMzQ

🔗 Instalar Netbeans 11 en Windows 10: https://www.youtube.com/watch?v=EouitrKS6Cw

🔗 Descargar e Instalar Netbeans 11 en ubuntu 18 04: https://www.youtube.com/watch?v=tWiX3Z5t5kQ

🔗 Netbeans Sublime Theme ?: https://www.youtube.com/watch?v=oAF2Q7mTZZM

🔗 Editar CSS directamenete en Chrome con Netbeans: https://www.youtube.com/watch?v=HlQs0a7R2cY

🔗 Esta lista de reproducción: https://www.youtube.com/playlist?list=PLCTD_CpMeEKTT-qEHGqZH3fkBgXH4GOTF
Codigos en gdrive: https://drive.google.com/file/d/1M6c0VYqrzpq6KwdWkrkw7Aalm8FkdITH/view?usp=sharing
Gracias por apoyar este canal: https://www.patreon.com/programadornovato?fan_landing=true

🔗 Facebook: https://facebook.com/ProgramadorNovatoOficial
🔗 Twitter: https://twitter.com/programadornova
🔗 Linkedin: https://www.linkedin.com/in/programadornovato/
🔗 Instagram: https://www.instagram.com/programadornovato/

Anterior tutorial Siguiente tutorial

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *