Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Synchonize frame size with screen resolution Posted by GyronMkwebo on 11 Jan 2007 at 3:36 AM
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.
Report
Re: Synchonize frame size with screen resolution Posted by pah on 11 Jan 2007 at 4:09 AM
: 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 
   }
}


Report
Re: Synchonize frame size with screen resolution Posted by GyronMkwebo on 11 Jan 2007 at 6:13 AM
: : 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?
Report
Re: Synchonize frame size with screen resolution Posted by pah on 11 Jan 2007 at 7:23 AM
: : 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) you have replaced the two parameters first width and then the height!;
 the constuctor is setBounds(int x,int y, int width,int height)
:      
 
:      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?
:

the first think which i see is the marked codesnap, try it with the the right variables. And the code looks on the first look little confusing for me. Check what your caller does with the frame!.
Report
Re: Synchonize frame size with screen resolution Posted by GyronMkwebo on 12 Jan 2007 at 2:26 AM
: : : 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) you have replaced the two parameters first width and then the height!;
:  the constuctor is setBounds(int x,int y, int width,int height)
: :      
:  
: :      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?
: :
:
: the first think which i see is the marked codesnap, try it with the the right variables. And the code looks on the first look little confusing for me. Check what your caller does with the frame!.
:

Yeah, it works, the 'form' gets 'Maximized'. Another question (sorry to nag) is: After i pop up a form (frame) and i want to force users to respond to the form (sort of locking focus onto the form), how would i do that?
Report
Re: Synchonize frame size with screen resolution Posted by pah on 12 Jan 2007 at 3:04 AM


: Yeah, it works, the 'form' gets 'Maximized'. Another question (sorry to nag) is: After i pop up a form (frame) and i want to force users to respond to the form (sort of locking focus onto the form), how would i do that?
:

you can use the requestFocus() methode of the frame object should do this.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.