: : Hie, i am new to java and want to design a GUI for mySQL database. How do i synchronize the frame size with the current screen resolution? I would need to make sure that the forms (actually frames), come up with the right size to go hand in hand with the current resolution settings on the screen.
: : Please help.
: :
: you can get the screensize with the Methode getScreenSize of the Class
: Toolkit....
:
: lets say you have a normal frame ....... in the constructor you can
: set the setSize of the frame as follows
:
:
: public class NewJFrame extends javax.swing.JFrame{
:
: public NewJFrame(){
: initComponents();
: this.setSize(this.getToolkit().getScreenSize());
: }
:
: public static void main(String args[]){
: java.awt.EventQueue.invokeLater(new Runnable(){
: public void run(){
: new JFrame().setVisible(true);
: }
: }};
: }
:
: private void initComponents(){
: //set teh default close operation etc here....
: //and the layoutmanager.........
: //if you have a good ide it does it all for you
: }
: }
:
:
: I was trying this
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JFrame;;
public class FrmMainForm extends JMenuBar {
String[] fileItems = new String[] { "New", "Set User Privileges", "Log in as different user", "Exit" };
String[] editItems = new String[] { "Undo", "Cut", "Copy", "Paste" };
char[] fileShortcuts = { 'N','O','S','X' };
char[] editShortcuts = { 'Z','X','C','V' };
public FrmMainForm() {
initComponents();
}
public void DisplayForm() {
JFrame frame = new JFrame("Powerspeed Electrical: - Pricing system");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(new FrmMainForm());
Dimension screenDim=Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds(0, 0, screenDim.height, screenDim.width);
frame.setVisible(true);
}
public void initComponents(){
JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Edit");
// Assemble the File menus with mnemonics
ActionListener printListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.out.println("Menu item [" + event.getActionCommand() +
"] was pressed.");
if (event.getActionCommand()=="Log in as different user"){
FrmLogIn new_Log=new FrmLogIn();
new_Log.DisplayForm();
}
}
};
for (int i=0; i < fileItems.length; i++) {
JMenuItem item = new JMenuItem(fileItems[i]);
item.addActionListener(printListener);
fileMenu.add(item);
}
// Assemble the File menus with keyboard accelerators
for (int i=0; i < editItems.length; i++) {
JMenuItem item = new JMenuItem(editItems[i]);
item.setAccelerator(KeyStroke.getKeyStroke(editShortcuts[i],
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
item.addActionListener(printListener);
editMenu.add(item);
}
// Insert a separator in the Edit Menu in Position 1 after "Undo"
editMenu.insertSeparator(1);
//insert seperators for the file menu
fileMenu.insertSeparator(1);
fileMenu.insertSeparator(4);
// Finally, add all the menus to the menu bar
add(fileMenu);
add(editMenu);
}
}
the public function DispalyForm is invoked from other classes and this brings up the form onto the screen, but it still doesn't fill the screen.
I tried your idea and the frame came on the screen, even smaller, in fact, so small that i could hardly see it! What do you think is the problem?