How to using pack() in the SingleFrameApplication ?

T

tobleron

Hi,

I have Main.Java code like this :

==========
package ecgterminal3;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

public class Main extends SingleFrameApplication {

@Override protected void startup() {
show(new Login(this));
}

@Override protected void configureWindow(java.awt.Window root) {
}

public static Main getApplication() {
return Application.getInstance(Main.class);
}

public static void main(String[] args) {
Application.launch(Main.class, args);
}

}
=======

When the code runs, it will shows the first form named Login.Java. The
problem is, if I continue to called another forms, it will shown in
1st form's size, even the other forms have their own sizes. How to
open forms in their own sizes by using SingleFrameApplication ?

Many thanks in advance.
 
T

tobleron

Hi, sorry, actually it's Main.java (not Main.Java). Here the code of
Main.java :

===========
package ecgterminal3;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

public class Main extends SingleFrameApplication {

@Override protected void startup() {
show(new Login(this));
}

@Override protected void configureWindow(java.awt.Window root) {
}

public static Main getApplication() {
return Application.getInstance(Main.class);
}

public static void main(String[] args) {
Application.launch(Main.class, args);
}

}
===========

And here the code of Login.java :

========
package ecgterminal3;

import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.Action;
import java.sql.*;
import javax.swing.JDialog;
import javax.swing.JFrame;

public class Login extends javax.swing.JDialog {

public Login(SingleFrameApplication app) {
initComponents();
}

public Login(javax.swing.JFrame app) {
initComponents();
}

public Login(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}


@Action public void doLogin() {
String url = "jdbc:mysql://localhost:3306/dicom?
jdbcCompliantTruncation=false";
Connection con;
PreparedStatement passwordLookup ;

try {
Class.forName("com.mysql.jdbc.Driver");
} catch(java.lang.ClassNotFoundException e) {
System.err.println(e);
}

try {
con = DriverManager.getConnection(url, "root", "");
String sql = "SELECT userid,passwd FROM user WHERE userid
= BINARY ? AND passwd = BINARY ?";
passwordLookup = con.prepareStatement(sql);
char[] passwdnya = passwdTxt.getPassword();
String convertedChars = new String(passwdnya);
passwordLookup.setString(1, userIDTxt.getText().trim());
passwordLookup.setString(2, convertedChars.trim());
ResultSet result = passwordLookup.executeQuery();

if (result.next()) {
setVisible(false);
if (ecgMenuBox == null) {
JFrame mainFrame =
Main.getApplication().getMainFrame();
//mainFrame.pack();
ecgMenuBox = new ECGMenu(mainFrame);
//pack();

ecgMenuBox.setLocationRelativeTo(mainFrame);
}
Main.getApplication().show(ecgMenuBox);
}
else {
setVisible(false);
if (loginWarningBox == null) {
JFrame mainFrame =
Main.getApplication().getMainFrame();
//mainFrame.setSize(100,80);
loginWarningBox = new
LoginWarning(mainFrame);

loginWarningBox.setLocationRelativeTo(mainFrame);
}
Main.getApplication().show(loginWarningBox);
}
result.close();
passwordLookup.close();
con.close();
} catch(SQLException e) {
setVisible(false);
if (noConBox == null) {
JFrame mainFrame =
Main.getApplication().getMainFrame();
noConBox = new NoDBCon(mainFrame);
noConBox.setLocationRelativeTo(mainFrame);
}
Main.getApplication().show(noConBox);
}
}


@Action public void eXit() {
Main.getApplication().exit();
}

/** 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")
// <editor-fold defaultstate="collapsed" desc="Generated
Code">
private void initComponents() {

loginPanel = new javax.swing.JPanel();
loginLabel = new javax.swing.JLabel();
userIDLabel = new javax.swing.JLabel();
passwdLabel = new javax.swing.JLabel();
userIDTxt = new javax.swing.JTextField();
loginButton = new javax.swing.JButton();
exitButton = new javax.swing.JButton();
passwdTxt = new javax.swing.JPasswordField();


setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setName("Form"); // NOI18N

loginPanel.setName("loginPanel"); // NOI18N

org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(ecgterminal3.Main.class).getContext().getResourceMap(Login.class);
loginLabel.setFont(resourceMap.getFont("loginLabel.font")); //
NOI18N

loginLabel.setText(resourceMap.getString("loginLabel.text")); //
NOI18N
loginLabel.setName("loginLabel"); // NOI18N


userIDLabel.setText(resourceMap.getString("userIDLabel.text")); //
NOI18N
userIDLabel.setName("userIDLabel"); // NOI18N


passwdLabel.setText(resourceMap.getString("passwdLabel.text")); //
NOI18N
passwdLabel.setName("passwdLabel"); // NOI18N

userIDTxt.setText(resourceMap.getString("userIDTxt.text")); //
NOI18N
userIDTxt.setName("userIDTxt"); // NOI18N

javax.swing.ActionMap actionMap =
org.jdesktop.application.Application.getInstance(ecgterminal3.Main.class).getContext().getActionMap(Login.class,
this);
loginButton.setAction(actionMap.get("doLogin")); // NOI18N

loginButton.setText(resourceMap.getString("loginButton.text")); //
NOI18N
loginButton.setName("loginButton"); // NOI18N

exitButton.setAction(actionMap.get("eXit")); // NOI18N

exitButton.setText(resourceMap.getString("exitButton.text")); //
NOI18N
exitButton.setName("exitButton"); // NOI18N

passwdTxt.setText(resourceMap.getString("passwdTxt.text")); //
NOI18N
passwdTxt.setName("passwdTxt"); // NOI18N

javax.swing.GroupLayout loginPanelLayout = new
javax.swing.GroupLayout(loginPanel);
loginPanel.setLayout(loginPanelLayout);
loginPanelLayout.setHorizontalGroup(

loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(loginPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(loginLabel)
.addGroup(loginPanelLayout.createSequentialGroup()
.addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(userIDLabel)
.addComponent(passwdLabel))
.addGap(21, 21, 21)
.addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(passwdTxt,
javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
.addComponent(userIDTxt,
javax.swing.GroupLayout.Alignment.LEADING))))
.addGroup(loginPanelLayout.createSequentialGroup()
.addComponent(loginButton)
.addGap(18, 18, 18)
.addComponent(exitButton)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
loginPanelLayout.setVerticalGroup(

loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(loginPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(loginLabel)
.addGap(18, 18, 18)
.addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(userIDLabel)
.addComponent(userIDTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(passwdLabel)
.addComponent(passwdTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(loginButton)
.addComponent(exitButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 257, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(loginPanel,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)))
);
layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 172, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(loginPanel,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)))
);

pack();
}// </editor-fold>

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Login dialog = new Login(new javax.swing.JFrame(),
true);
dialog.addWindowListener(new
java.awt.event.WindowAdapter() {
public void
windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton exitButton;
private javax.swing.JButton loginButton;
private javax.swing.JLabel loginLabel;
private javax.swing.JPanel loginPanel;
private javax.swing.JLabel passwdLabel;
private javax.swing.JPasswordField passwdTxt;
private javax.swing.JLabel userIDLabel;
private javax.swing.JTextField userIDTxt;
// End of variables declaration

private JDialog ecgMenuBox;
private JDialog loginWarningBox;
private JDialog noConBox;
}
========
 
T

tobleron

Hi, the problem has been solved when I unchecked the resizeable option
in NetBeans. Thank you for your attention and help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top