Guest User

ToolBar in a Java window

a guest
Jan 6th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ===================
  2. JentWindowJava.java
  3. ===================
  4.  
  5. import javax.swing.JFrame;
  6. /**
  7.  *
  8.  * @author Jent Digital Solutions
  9.  * @param
  10.  *
  11.  */
  12. public class JentWindow extends JFrame {
  13.        
  14.     private static final long serialVersionUID = 6305168658694781802L;
  15.  
  16.     /**
  17.      *
  18.      * @param JentTitle Defines a window title
  19.      * @param jexit If true, when the X of window is pressed, the window closes
  20.      * @param jwidth Defines the window width
  21.      * @param jheight Defines the window height
  22.      * @param jresize Defines is the window can be resizable or not
  23.      * @param jmenu Defines is the window have a menu bar or not
  24.      * @param buttonB If the tool bar is closed, if buttonB is true, window also is closed
  25.      */
  26.     public void instWindow(String JentTitle, boolean jexit, int jwidth, int jheight, boolean jresize, boolean jmenu, boolean buttonB){
  27.    
  28.         if (jexit) {
  29.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30.     }
  31.    
  32.     //Instantiates a menu bar into the window
  33.     if (jmenu) {
  34.     JentMenuBar menuBar = new JentMenuBar(); //Instantiates an object to make menu works
  35.     menuBar.JentConfigureMenuBar(true, true, true); //Calls method that pass two arguments: file menu and edit menu.
  36.     setJMenuBar(menuBar); //Configures menu bar
  37.     }
  38.    
  39.     //Instantiates a button bar (tool bar) into the window
  40.     if (buttonB){
  41.         JentButtonBar buttonBar = new JentButtonBar();
  42.         buttonBar.instButtonBar(false);
  43.         }
  44.    
  45.     setTitle(JentTitle);
  46.     setSize(jwidth, jheight);
  47.     setVisible(true);
  48.     setLocationRelativeTo(null); //center the window at the screen
  49.     setResizable(jresize); //Don't resize
  50.     setLayout(null); ///Don't uses layout
  51.     }
  52.    
  53.    
  54. }
  55.  
  56. ==================
  57. JentButtonBar.java
  58. ==================
  59.  
  60. import java.awt.BorderLayout;
  61. import java.awt.Container;
  62. import javax.swing.JButton;
  63. import javax.swing.JFrame;
  64. import javax.swing.JToolBar;
  65.  
  66. public class JentButtonBar extends JFrame {
  67.    
  68.     private static final long serialVersionUID = 1L;
  69.    
  70.     JToolBar jent_toolbar = new JToolBar();
  71.  
  72.     public JentButtonBar(){
  73.         super("TOOLBAR");
  74.     }
  75.    
  76.     /**
  77.      * This class instantiates a Tool Bar on the window
  78.      * If jexitonclose, the bar closes when X is pressed
  79.      */
  80.     public void instButtonBar(boolean jexitonclose){
  81.  
  82.     jent_toolbar.add(new JButton("Abrir"));
  83.     jent_toolbar.add(new JButton("Novo"));
  84.     jent_toolbar.add(new JButton("Salvar"));
  85.     jent_toolbar.add(new JButton("Fechar"));
  86.    
  87.     Container pane = this.getContentPane();
  88.     //define como layout o layout de borda
  89.     pane.setLayout(new BorderLayout());
  90.  
  91.     //adiciona o toolbar no topo
  92.     pane.add(BorderLayout.NORTH, jent_toolbar);
  93.     jent_toolbar.setFloatable(false); //Não permite que a barra se mova na janela
  94.    
  95.     if (jexitonclose){
  96.    
  97.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  98.     }
  99.    
  100.     this.setSize(1024, 54);
  101.     this.setResizable(false);
  102.     this.setVisible(true);
  103.  
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment