Curso de Java Netbeans Completo☕ [85.- Area de Texto con scroll(JTextArea) ]
En este tutorial vamos a crear un Area de Texto con scroll(JTextArea) y jugaremos con sus propiedades como el texto, las columnas y filas. Tambien aprenderemos a colocar un scroll (JScrollPane).
Java swing: https://es.wikipedia.org/wiki/Swing_(biblioteca_gr%C3%A1fica)
Documentación de java: https://docs.oracle.com/javase/8/docs/api/
Codigo: https://github.com/programadornovato/java/commit/9ecb580684d84aae35be008d10db59d3e7f3ef56
package com.programadornovato.proy1;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
/**
*
* @author eugenio
*/
public class Ventana extends JFrame{
ArrayList <JPanel> panel=new ArrayList<JPanel>();
ArrayList <JLabel> etiqueta=new ArrayList<JLabel>();
ArrayList <JRadioButton> listaRb=new ArrayList<JRadioButton>();
JPanel contenedor=new JPanel();
JButton b1;
int num=4;
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);
this.getContentPane().add(contenedor);
contenedor.setLayout(null);
//this.num= Integer.parseInt(JOptionPane.showInputDialog("Humano cuantos paneles quieres"));
//iniciarPaneles();
//inicaEtiquetas();
//iniciarBotones();
//iniciarRadio();
//iniciaCampoTexto();
iniciaAreaTexto();
}
public void iniciaAreaTexto(){
JTextArea areaTexto=new JTextArea();
//areaTexto.setBounds(100, 100, 300, 150);
areaTexto.setText("Humano este es un texto");
areaTexto.append("\nHumano aqui hay mas texto");
areaTexto.append("\nHumano aqui hay mas texto\n");
areaTexto.setEnabled(true);
areaTexto.setEditable(true);
JScrollPane scroll=new JScrollPane(areaTexto);
scroll.setBounds(100, 100, 300, 150);
this.contenedor.add(scroll);
System.out.println(areaTexto.getText());
}
public void iniciaCampoTexto(){
JTextField campoText=new JTextField();
campoText.setText("HHHHHHHHHHHHHHHHHHHH");
JTextField campoText2=new JTextField();
campoText2.setText("HHHHHHHHHHHHHHHHHHHH");
campoText2.setFont(new Font(Font.SERIF,Font.BOLD,20));
campoText2.setBackground(new Color(0, 10, 255));
campoText2.setForeground(new Color(255, 240, 0));
//campoText.setBounds(100, 100, 300, 25);
campoText.setColumns(20);
campoText2.setColumns(20);
this.contenedor.add(campoText);
this.contenedor.add(campoText2);
System.out.println(campoText);
}
private void iniciarRadio() {
ButtonGroup grupo=new ButtonGroup();
String textoOpciones[]=
{
"Humano dame click",
"No no no, dame click a mi",
"Dame click y unete al lado oscuro"
};
for (int i = 0; i < textoOpciones.length; i++) {
listaRb.add(new JRadioButton());
listaRb.get(i).setText(textoOpciones[i]);
listaRb.get(i).setBounds(100, 100+(i*50), 350, 50);
listaRb.get(i).setFont(new Font(Font.SERIF,Font.BOLD,15));
if(i==2){
listaRb.get(i).setSelected(true);
}
grupo.add(listaRb.get(i));
this.contenedor.add(listaRb.get(i));
}
/*
JRadioButton rb=new JRadioButton("Opcion 1");
rb.setBounds(100, 100, 350, 50);
rb.setEnabled(true);
this.contenedor.add(rb);
*/
}
protected void iniciarPaneles() {
JPanel contenedor=new JPanel();
this.getContentPane().add(contenedor);
contenedor.setBackground(Color.red);
for(int i=0;i<this.num;i++){
this.panel.add(new JPanel());
contenedor.add(this.panel.get(i));
this.panel.get(i).setBackground(new Color(i*50, i*50, i*50));
}
contenedor.setLayout(new BoxLayout(contenedor, BoxLayout.X_AXIS));
}
protected void inicaEtiquetas() {
for(int i=0;i<this.num;i++){
this.etiqueta.add(new JLabel("Hola"+(i+1), new ImageIcon(new ImageIcon("images/netbeans 11.png").getImage().getScaledInstance(60, 60, Image.SCALE_DEFAULT)) , SwingConstants.RIGHT ));
this.etiqueta.get(i).setForeground(Color.white);
this.panel.get(i).add(this.etiqueta.get(i));
}
}
public void setTextos(String textos[]){
}
protected void iniciarBotones() {
b1=new JButton("Dale like!!!");
JPanel contenedor=new JPanel();
this.getContentPane().add(contenedor);
contenedor.add(b1);
contenedor.setLayout(null);
b1.setBounds(100, 100, 250, 50);
b1.setText("Que le des like!!!");
b1.setEnabled(true);
b1.setMnemonic(KeyEvent.VK_J);
b1.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 15));
b1.setBackground(new Color(193, 9, 9));
b1.setForeground(Color.WHITE);
b1.setIcon( new ImageIcon( new ImageIcon("images/like.png").getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH) ));
}
}
🔗 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