Hallo ich habe versucht ein AWT Programm in ein SWING programm umzubasteln. Wobei ich das GridBagLayout verwendet habe. Dabei habe icheinfach die Komponenten ausgetauscht. Ledier sieht das ergebnis in swing total verschoben aus. Wieso?
Gruß niesel
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
class Sqlswing extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
JTextField SQLQuery;
JButton OK;
JTextArea SQLView;
JMenuBar mb;
Mymysql mysql;
String resulttext, querystring;
ResultSet r;
public Sqlswing() {
setTitle("SQL-Viewer");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
SQLQuery = new JTextField();
OK = new JButton("OK");
SQLView = new JTextArea();
mb = new JMenuBar();
mysql=new Mymysql();
mysql.connect();
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
//Menubar
c.gridx=0; c.gridy=0; c.gridheight=1; c.gridwidth=8;
c.fill = GridBagConstraints.HORIZONTAL;
c.insets=new Insets(5,5,5,5);
//add(mb, c);
c.gridx=0; c.gridy=1; c.gridheight=6; c.gridwidth=8;
c.fill = GridBagConstraints.BOTH;
add(SQLView, c);
c.gridx=0; c.gridy=7; c.gridheight=1; c.gridwidth=3;
c.fill = GridBagConstraints.BOTH;
add(OK, c);
c.gridx=3; c.gridy=7; c.gridheight=1; c.gridwidth=8;
c.fill = GridBagConstraints.BOTH;
add(SQLQuery, c);
OK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//mymysql.query(SQLQuery.getText());
querystring=SQLQuery.getText();
resulttext=mysql.execute(querystring);
SQLView.setText(resulttext);
}
});
pack();
setVisible(true);
}
public static void main(String[] arg) {
new Sqlswing();
}
}
Gruß niesel