Hallo,
ich habe ein wenig Probleme mit einem JDialog Fenster, das ich aus meinem Hauptprogramm mit einem Parameter StrUser öffne.
Gedacht ist folgender Ablauf:
Ich starte die Instanz des JDialogs aus dem Hauptprogramm aus mit folgendem Code:
showUserInformation sUI = new showUserInformation(StrUser);
Dann wird das Fenster mit seinen Labels und Textfeldern erzeugt.
Im Anschluss werden einige Strings in der Funktion initValue() durch eine Datenbankabfrage beschrieben. Ein String soll dann im Anschluss das Textfeld tfLoginName mit einer setText Methode beschreiben.
Jedoch öffnet sich das Fenster bei mir ganz normal. In der Kommandozeile werden die Datenbankabfragen korrekt in die Strings gespeichert. Jedoch wird der String StrLoginName nicht in das Textfeld tfLoginName gespeichert.
Woran kann das liegen?
ich habe ein wenig Probleme mit einem JDialog Fenster, das ich aus meinem Hauptprogramm mit einem Parameter StrUser öffne.
Gedacht ist folgender Ablauf:
Ich starte die Instanz des JDialogs aus dem Hauptprogramm aus mit folgendem Code:
showUserInformation sUI = new showUserInformation(StrUser);
Dann wird das Fenster mit seinen Labels und Textfeldern erzeugt.
Im Anschluss werden einige Strings in der Funktion initValue() durch eine Datenbankabfrage beschrieben. Ein String soll dann im Anschluss das Textfeld tfLoginName mit einer setText Methode beschreiben.
Jedoch öffnet sich das Fenster bei mir ganz normal. In der Kommandozeile werden die Datenbankabfragen korrekt in die Strings gespeichert. Jedoch wird der String StrLoginName nicht in das Textfeld tfLoginName gespeichert.
Woran kann das liegen?
Java:
package GUI;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import Handler.dbHandler;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JPasswordField;
import java.awt.Component;
import javax.swing.Box;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class showUserInformation extends JDialog {
private final JPanel contentPanel = new JPanel();
private JTextField tfName;
private JTextField tfEmail;
private JTextField tfTelefon;
private JPasswordField tfPassword;
private JTextField tfLoginName = new JTextField();
private String StrUserParameter;
private String StrUserName;
private String StrLogin;
private String StrEmail;
private String StrTelephone;
private String StrPosition;
private String StrUserRole;
/**
* Launch the application.
*/
public void initWindow(String StrUser) {
StrUserParameter = StrUser;
showUserInformation dialog = new showUserInformation();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
dialog.setAlwaysOnTop(true);
initValues();
}
public void initValues(){
System.out.println("Init aufgerufen");
dbHandler db = new dbHandler();
// Datenbankabfrage wird jeweils in einen String gespeichert
StrLogin = db.getUserInfo("login", StrUserParameter);
StrUserName = db.getUserInfo("name", StrUserParameter);
StrEmail = db.getUserInfo("email", StrUserParameter);
StrTelephone = db.getUserInfo("telephone", StrUserParameter);
StrPosition = db.getUserInfo("position", StrUserParameter);
StrUserRole = db.getUserInfo("userrole", StrUserParameter);
// Konsolenausgabe, ob Datensätze korrekt sind
System.out.println(StrLogin);
System.out.println(StrUserName);
System.out.println(StrEmail);
System.out.println(StrTelephone);
System.out.println(StrPosition);
System.out.println(StrUserRole);
// Strings in die Textfelder schreiben
tfLoginName.setText(StrLogin);
}
public showUserInformation() {
setTitle("Benutzerinformationen");
setBounds(100, 100, 450, 251);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
GridBagLayout gbl_contentPanel = new GridBagLayout();
gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
contentPanel.setLayout(gbl_contentPanel);
{
Component verticalGlue = Box.createVerticalGlue();
GridBagConstraints gbc_verticalGlue = new GridBagConstraints();
gbc_verticalGlue.insets = new Insets(0, 0, 5, 5);
gbc_verticalGlue.gridx = 0;
gbc_verticalGlue.gridy = 0;
contentPanel.add(verticalGlue, gbc_verticalGlue);
}
{
JLabel lblLogin = new JLabel("Login:");
GridBagConstraints gbc_lblLogin = new GridBagConstraints();
gbc_lblLogin.anchor = GridBagConstraints.EAST;
gbc_lblLogin.insets = new Insets(0, 0, 5, 5);
gbc_lblLogin.gridx = 0;
gbc_lblLogin.gridy = 1;
contentPanel.add(lblLogin, gbc_lblLogin);
}
{
GridBagConstraints gbc_tfLoginName = new GridBagConstraints();
gbc_tfLoginName.insets = new Insets(0, 0, 5, 0);
gbc_tfLoginName.fill = GridBagConstraints.HORIZONTAL;
gbc_tfLoginName.gridx = 1;
gbc_tfLoginName.gridy = 1;
contentPanel.add(tfLoginName, gbc_tfLoginName);
tfLoginName.setColumns(10);
}
{
JLabel lblName = new JLabel("Name:");
GridBagConstraints gbc_lblName = new GridBagConstraints();
gbc_lblName.anchor = GridBagConstraints.EAST;
gbc_lblName.insets = new Insets(0, 0, 5, 5);
gbc_lblName.gridx = 0;
gbc_lblName.gridy = 2;
contentPanel.add(lblName, gbc_lblName);
}
{
tfName = new JTextField();
GridBagConstraints gbc_tfName = new GridBagConstraints();
gbc_tfName.insets = new Insets(0, 0, 5, 0);
gbc_tfName.fill = GridBagConstraints.HORIZONTAL;
gbc_tfName.gridx = 1;
gbc_tfName.gridy = 2;
contentPanel.add(tfName, gbc_tfName);
tfName.setColumns(10);
}
{
JLabel lblEmail = new JLabel("Email:");
GridBagConstraints gbc_lblEmail = new GridBagConstraints();
gbc_lblEmail.anchor = GridBagConstraints.EAST;
gbc_lblEmail.insets = new Insets(0, 0, 5, 5);
gbc_lblEmail.gridx = 0;
gbc_lblEmail.gridy = 3;
contentPanel.add(lblEmail, gbc_lblEmail);
}
{
tfEmail = new JTextField();
GridBagConstraints gbc_tfEmail = new GridBagConstraints();
gbc_tfEmail.insets = new Insets(0, 0, 5, 0);
gbc_tfEmail.fill = GridBagConstraints.HORIZONTAL;
gbc_tfEmail.gridx = 1;
gbc_tfEmail.gridy = 3;
contentPanel.add(tfEmail, gbc_tfEmail);
tfEmail.setColumns(10);
}
{
JLabel lblTelefon = new JLabel("Telefon:");
GridBagConstraints gbc_lblTelefon = new GridBagConstraints();
gbc_lblTelefon.anchor = GridBagConstraints.EAST;
gbc_lblTelefon.insets = new Insets(0, 0, 5, 5);
gbc_lblTelefon.gridx = 0;
gbc_lblTelefon.gridy = 4;
contentPanel.add(lblTelefon, gbc_lblTelefon);
}
{
tfTelefon = new JTextField();
GridBagConstraints gbc_tfTelefon = new GridBagConstraints();
gbc_tfTelefon.insets = new Insets(0, 0, 5, 0);
gbc_tfTelefon.fill = GridBagConstraints.HORIZONTAL;
gbc_tfTelefon.gridx = 1;
gbc_tfTelefon.gridy = 4;
contentPanel.add(tfTelefon, gbc_tfTelefon);
tfTelefon.setColumns(10);
}
{
JLabel lblPosition = new JLabel("Position:");
GridBagConstraints gbc_lblPosition = new GridBagConstraints();
gbc_lblPosition.anchor = GridBagConstraints.EAST;
gbc_lblPosition.insets = new Insets(0, 0, 5, 5);
gbc_lblPosition.gridx = 0;
gbc_lblPosition.gridy = 5;
contentPanel.add(lblPosition, gbc_lblPosition);
}
{
JComboBox cbPosition = new JComboBox();
GridBagConstraints gbc_cbPosition = new GridBagConstraints();
gbc_cbPosition.insets = new Insets(0, 0, 5, 0);
gbc_cbPosition.fill = GridBagConstraints.HORIZONTAL;
gbc_cbPosition.gridx = 1;
gbc_cbPosition.gridy = 5;
contentPanel.add(cbPosition, gbc_cbPosition);
}
{
JLabel lblPasswort = new JLabel("Passwort:");
GridBagConstraints gbc_lblPasswort = new GridBagConstraints();
gbc_lblPasswort.anchor = GridBagConstraints.EAST;
gbc_lblPasswort.insets = new Insets(0, 0, 5, 5);
gbc_lblPasswort.gridx = 0;
gbc_lblPasswort.gridy = 6;
contentPanel.add(lblPasswort, gbc_lblPasswort);
}
{
tfPassword = new JPasswordField();
GridBagConstraints gbc_tfPassword = new GridBagConstraints();
gbc_tfPassword.insets = new Insets(0, 0, 5, 0);
gbc_tfPassword.fill = GridBagConstraints.HORIZONTAL;
gbc_tfPassword.gridx = 1;
gbc_tfPassword.gridy = 6;
contentPanel.add(tfPassword, gbc_tfPassword);
}
{
JLabel lblBenutzerrechte = new JLabel("Benutzerrechte:");
GridBagConstraints gbc_lblBenutzerrechte = new GridBagConstraints();
gbc_lblBenutzerrechte.anchor = GridBagConstraints.EAST;
gbc_lblBenutzerrechte.insets = new Insets(0, 0, 5, 5);
gbc_lblBenutzerrechte.gridx = 0;
gbc_lblBenutzerrechte.gridy = 7;
contentPanel.add(lblBenutzerrechte, gbc_lblBenutzerrechte);
}
{
JComboBox cbRules = new JComboBox();
GridBagConstraints gbc_cbRules = new GridBagConstraints();
gbc_cbRules.insets = new Insets(0, 0, 5, 0);
gbc_cbRules.fill = GridBagConstraints.HORIZONTAL;
gbc_cbRules.gridx = 1;
gbc_cbRules.gridy = 7;
contentPanel.add(cbRules, gbc_cbRules);
}
{
Component verticalGlue = Box.createVerticalGlue();
GridBagConstraints gbc_verticalGlue = new GridBagConstraints();
gbc_verticalGlue.gridx = 1;
gbc_verticalGlue.gridy = 8;
contentPanel.add(verticalGlue, gbc_verticalGlue);
}
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("Speichern");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Abbruch");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
}
}