.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúA todo ésto, si deseo moverlo, tendría que modificar esta línea, no?
CitarY tengo una duda sobre esta línea:
Código:
DefaultTableModel defaultTableModel = new DefaultTableModel(3,4);
Esos números (el 3 y el 4), representan la cantidad de filas y columnas? Si por ejemplo quiero cargar un fichero con datos, habrá que usar otro método para que coloque la cantidad de filas y columnas que quiero? ¿Qué podría usar?
CitarUsé el código, y sin embargo no pasó nada tampoco, es más me tiró error =S?
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class FrmPrincipal extends JFrame {
public FrmPrincipal() {
JScrollPane jScrollPane = new JScrollPane();
DefaultTableModel defaultTableModel = new DefaultTableModel(3,4);
JTable jTable = new JTable(defaultTableModel);
jScrollPane.getViewport().add(jTable);
add(jScrollPane);
setSize(300, 400);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
FrmPrincipal frmPrincipal = new FrmPrincipal();
frmPrincipal.setVisible(true);
}
}
package javaapplication7;
public class FrmPrincipal extends javax.swing.JFrame {
public FrmPrincipal() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
----->basura autogenerada aqui
}// </editor-fold>
private void txtMesesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnMostrarActionPerformed(java.awt.event.ActionEvent evt) {
FrmContratos frmContratos = new FrmContratos(this,true);
frmContratos.setMeses(txtMeses.getText());
frmContratos.setVisible(true);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FrmPrincipal().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnMostrar;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField txtMeses;
// End of variables declaration
}
package javaapplication7;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class FrmContratos extends javax.swing.JDialog {
private ServicioDeContratos servicioDeContratos = new ServicioDeContratos();
public FrmContratos(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
----->basura autogenerada aqui
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JTabbedPane jTabbedPane1;
// End of variables declaration
void setMeses(String textoMeses) {
String[] meses = textoMeses.split(",");
for (String mes : meses) {
agreagTab(mes);
}
}
private void agreagTab(String mes) {
jTabbedPane1.addTab(mes, creaPanelParaElMes(mes));
}
private JPanel creaPanelParaElMes(String mes) {
JPanel jPanel = new JPanel();
jPanel.setLayout(new BorderLayout());
jPanel.add(new JTextArea(servicioDeContratos.getContratoDelMes(mes)));
return jPanel;
}
}
package javaapplication7;
public class ServicioDeContratos {
public String getContratoDelMes(String mes) {
return "Contrato Del mes:" + mes + "\nblalalba lbala b l albla lal balbl\n\nblalalba lbala b l albla lal balbl";
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication7;
/**
*
* @author luis
*/
public class NewJFrame extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
setTitle("titulo");<---Aqui agrego todo el codigo que quiera sin ninguna restricion
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
// End of variables declaration
}
package javaapplication7;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class PanContacto extends JPanel {
private JPanel pnEtiquetas = new JPanel();
private JPanel panComponentes = new JPanel();
private JPanel panPrincipal = new JPanel();
private JPanel panBotones =new JPanel();
private JLabel lblNombre = new JLabel("Nombre");
private JLabel lblApellido = new JLabel("Apellido");
private JLabel lblDirecion = new JLabel("Direcion");
private JLabel lblEdad = new JLabel("Edad");
private JLabel lblPais = new JLabel("Pais");
private JTextField txtNombre = new JTextField();
private JTextField txtApellido = new JTextField();
private JTextField txtDirecion = new JTextField();
private JTextField txtEdad = new JTextField();
private JTextField txtPais = new JTextField();
private JButton btnAceptar=new JButton("Aceptar");
private JButton btnCancelar=new JButton("Cancelar");
public PanContacto() {
setLayout(new BorderLayout());
add(panPrincipal, BorderLayout.NORTH);
panPrincipal.setLayout(new BorderLayout());
panPrincipal.add(pnEtiquetas, BorderLayout.WEST);
panPrincipal.add(panComponentes, BorderLayout.CENTER);
panPrincipal.add(panBotones,BorderLayout.SOUTH);
pnEtiquetas.setLayout(new GridLayout(5, 1));
pnEtiquetas.add(lblNombre);
pnEtiquetas.add(lblApellido);
pnEtiquetas.add(lblDirecion);
pnEtiquetas.add(lblEdad);
pnEtiquetas.add(lblPais);
panComponentes.setLayout(new GridLayout(5, 1));
panComponentes.add(txtNombre);
panComponentes.add(txtApellido);
panComponentes.add(txtDirecion);
panComponentes.add(txtEdad);
panComponentes.add(txtPais);
panBotones.setLayout(new FlowLayout(FlowLayout.RIGHT));
panBotones.add(btnAceptar);
panBotones.add(btnCancelar);
}
}
}
package javaapplication7;
import javax.swing.JFrame;
public class Apliaccion {
public void comiensa() {
JFrame frame = new JFrame("");
frame.add(new PanContacto());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String arg[]) {
new Apliaccion().comiensa();
}
}