Hola amigo. Les cuento mi problema. Estoy haciendo una pantalla para el oingreso de facturas Y lo hago asi: Para posicionar los label y text he usado setBounds que me ha dado resultado.
lbl_dire.setText("Direccion:");
getContentPane().add(lbl_dire);
lbl_dire.setBounds(300 ,30 ,150 ,16);
Mi problema esta con el jpanel que no se como posicionarlo en la ventana ya que no funciona el setBounds.
JTable table1 = new JTable(10, 8);
table1.setPreferredScrollableViewportSize(new Dimension(500,10));
JScrollPane scrollPane1 = new JScrollPane(table1);
//getContentPane().add(scrollPane1, BorderLayout.CENTER);
scrollPane1.setBounds(100, 100, 90, 26);
getContentPane().add(scrollPane1);
La cosa es que lo posiciona en la parte superior de la ventana.
Tonces mi duda es como bajarlo....
este es todo el codigo:
Código HTML:
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
public class Ventana_2 extends JFrame {
//Estados
//Texto
private JTextField Text_rut;
private JTextField Text_dire;
private JTextField Text_nmbr;
//Label
private JLabel lbl_rut;
private JLabel lbl_dire;
private JLabel lbl_nmbr;
private JLabel lbl_titu;
//Botones
private JButton btn_salir;
//-----------------------
//constructor
public Ventana_2(){
setTitle("Ingreso de Facturas");
setSize(900,600);
Text_rut = new JTextField();
Text_dire = new JTextField();
Text_nmbr = new JTextField();
lbl_titu = new JLabel();
lbl_rut = new JLabel();
lbl_dire = new JLabel();
lbl_nmbr = new JLabel();
btn_salir = new JButton();
//el contenedor es nulo
//getContentPane().setLayout(null);
//Titulo
lbl_titu.setText("SOLUCIONES Y SERIVIOS LTDA");
getContentPane().add(lbl_titu);
lbl_titu.setBounds(400 ,10 ,200 ,16);
getContentPane().add(lbl_titu);
//Label Rut
lbl_rut.setText("Rut:");
getContentPane().add(lbl_rut);
lbl_rut.setBounds(10 ,30 ,150 ,16);
//text Rut
//Text_rut.setText("Rut:");
Text_rut.setBounds(80 ,30 ,150 ,16);
getContentPane().add(Text_rut);
//Label Nombre
lbl_nmbr.setText("Nombre:");
getContentPane().add(lbl_nmbr);
lbl_nmbr.setBounds(10 ,50 ,150 ,16);
//text Nombre
//Text_rut.setText("");
Text_nmbr.setBounds(80 ,50 ,150 ,16);
getContentPane().add(Text_nmbr);
//Label Direccion
lbl_dire.setText("Direccion:");
getContentPane().add(lbl_dire);
lbl_dire.setBounds(300 ,30 ,150 ,16);
//text Direccion
//Text_rut.setText("");
Text_dire.setBounds(400 ,30 ,150 ,16);
getContentPane().add(Text_dire);
//accion cerrar del boton
btn_salir.setText("Cerrar");
btn_salir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Cmd_cerrar_ventana(evt);
}
});
getContentPane().add(btn_salir);
btn_salir.setBounds(600, 450, 90, 26);
//escuchador de cerrar
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
exitForm(evt);
}
});
//grilla
JTable table1 = new JTable(10, 8);
table1.setPreferredScrollableViewportSize(new Dimension(500,10));
JScrollPane scrollPane1 = new JScrollPane(table1);
//getContentPane().add(scrollPane1, BorderLayout.CENTER);
scrollPane1.setBounds(100, 100, 90, 26);
getContentPane().add(scrollPane1);
//table1.setForeground(Color.blue);
//table1.setBackground(Color.pink);
} //fin del constructor Ventana_2()
/*cerrar*/
private void exitForm(WindowEvent evt) {
System.exit(0);
}
//------------------------------------METODOS
public void Cmd_cerrar_ventana(ActionEvent evt){
System.exit(0);
}
//------------------------------------MAIN
public static void main(String[] args){
Ventana_2 Formulario = new Ventana_2();
//Formulario.pack();
Formulario.setVisible(true);
//new Ventana_2().show();
}
}//fin de la clase Ventana_2