Results 1 to 5 of 5
  1. #1
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

    Default status bar - its height is changed while resizing window.But Height must be same.

    hi friends !
    After a long break , its nice to meet you all .... : )

    I am working on creating a simple notepad application in which i setup menubar , text area and status bar. As there is no built-in class in java to create a status bar , i created a simple status bar . i am not good in handling layout managers . so , when resizing the window , all components in the Jframe are resized.
    how do i prevent statusbar from changing its height while resizing the window ? this is the code :
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    class Notepad extends JFrame {
    
    // Declaring menus.......
    	JMenuBar padmenu;
    	JMenu file,view,edit,format,help;
    	JMenuItem fnew,fopen,fsave,fsaveas,fexit,vstatusbar,frfont,frwordwrap,htopics,habout;
    	JMenuItem eundo,ecut,ecopy,epaste,edelete,efind,efindnext,ereplace,egoto,eselectall,etimedate;
    // Declaring status bar ....
    	StatusBar padstatus;
    // Declaring work area components ...
    	JScrollPane workareapane ;
    	JTextArea workarea;
    	JPanel content;
    // Defining Constructor...
    	public Notepad()	{
    
    		// setting layout of the JFrame ...
    	
    		setLayout( new BorderLayout());
    		content = new JPanel();
    		content.setLayout(new GridLayout());
    		// Creating Menu Bar and Menu Items....
    
    		padmenu = new JMenuBar();
    		setJMenuBar(padmenu);
    	
    		// creating Menus ...
    		file = new JMenu("File");
    		view = new JMenu("View");
    		edit = new JMenu("Edit");
    		format = new JMenu("Format");
    		help = new JMenu("Help");
    
    		// adding menus to menubar ...
    
    		padmenu.add(file);
    		padmenu.add(view);
    		padmenu.add(edit);
    		padmenu.add(format);
    		padmenu.add(help);
    
    		// creating file menu items ...
    		fnew = new JMenuItem("New");
    		fopen = new JMenuItem("Open");
    		fsave = new JMenuItem("Save");
    		fsaveas = new JMenuItem("Save As");
    		fexit = new JMenuItem("Exit");
    
    		// add file menu items to file menu...
    
    		file.add(fnew);
    		file.add(fopen);
    		file.add(fsave);
    		file.add(fsaveas);
    		file.add(fexit);
    
    		// creating view menu items ...
    
    		vstatusbar = new JMenuItem("Status Bar");
    
    		// adding view menu item to view menu ..
    
    		view.add(vstatusbar);
    
    		// creating edit menu items ...
    
    		eundo = new JMenuItem("Undo");
    		ecut = new JMenuItem("Cut");
    		ecopy = new JMenuItem("Copy");
    		epaste = new JMenuItem("Paste");
    		edelete = new JMenuItem("Delete");
    		efind = new JMenuItem("Find");
    		efindnext = new JMenuItem("Find Next");
    		ereplace = new JMenuItem("Replace");
    		egoto = new JMenuItem("Go To");
    		eselectall = new JMenuItem("Select All");
    		etimedate = new JMenuItem("Time/Date");
    
    		// adding menu items to edit menu...
    
    		edit.add(eundo);
    		edit.add(ecut);
    		edit.add(ecopy);
    		edit.add(epaste);
    		edit.add(edelete);
    		edit.add(efind);
    		edit.add(efindnext);
    		edit.add(ereplace);
    		edit.add(egoto);
    		edit.add(eselectall);
    		edit.add(etimedate);
    
    		// creating format menu items ..
    
    		frfont = new JMenuItem("Font");
    		frwordwrap = new JMenuItem("Word Wrap");
    
    		// addin format menu items to format menu ...
    
    		format.add(frfont);	
    		format.add(frwordwrap);
    
    		// creating help menu items ...
    
    		htopics = new JMenuItem("Help Topics");
    		habout = new JMenuItem("About");
    
    		// creating menu items 
    
    		help.add(htopics);
    		help.add(habout);
    
    		// creating work area components 
    
    		// creating rich text box .....
    
    		workarea = new JTextArea(35 ,80);
    
    		// creating scroll pane :(workareapane)
    		workareapane = new JScrollPane(workarea);
    		// adding scroll pane to JFrame
    
    		add(workareapane , BorderLayout.NORTH);
    
    		// creating status bar ...
    
    		padstatus =  new StatusBar();
    		content.add(padstatus);
    
    		add(content , BorderLayout.SOUTH);
    		// setting up window components ... 
    
    		setTitle("Notepad");
    		setSize(900,700);
    		setLocation(250 ,75 );
    		setVisible(true);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    	}
    
    	public static void main(String args[])	{
    
    	 new Notepad();
    	}
    }
    
    class StatusBar extends JLabel {
        
        /** Creates a new instance of StatusBar */
        public StatusBar() {
            super();
            super.setPreferredSize(new Dimension(100, 16));
            setMessage("Ready");
        }
        
        public void setMessage(String message) {
            setText(" "+message);        
        }        
    }
    Thanks

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: status bar - its height is changed while resizing window.But Height must be same.

    You say your problem is with a status bar, presumably placed at the bottom of the window, but the bulk of the code you posted appears to deal with menu items, menus and the menu bar, which shouldn't have anything to do with the stated problem. To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: status bar - its height is changed while resizing window.But Height must be same.

    I agree with DarrylBurke - get rid of everything concerning the menu and see what emerges. One point about expressing a problem in terms of a SSCCE is that it not only makes things easier for those you are describing the problem to, but it also allows *you* to see the elements of the problem without any distractions. In this case those elements would appear to be the various panels and their layout managers.

  4. #4
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

    Default Re: status bar - its height is changed while resizing window.But Height must be same.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    class Notepad extends JFrame {

    content = getContentPane();
    padstatus = new StatusBar();
    content.add(padstatus);

    add(content , BorderLayout.SOUTH);

    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public static void main(String args[]) {

    new Notepad();
    }
    }

    class StatusBar extends JLabel {

    /** Creates a new instance of StatusBar */
    public StatusBar() {
    super();
    super.setPreferredSize(new Dimension(100, 16));
    setMessage("Ready");
    }

    public void setMessage(String message) {
    setText(" "+message);
    }
    }

    how do we create a status bar with height of 20pixels to 25pixels ?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: status bar - its height is changed while resizing window.But Height must be same.

    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

    Did you go through the SSCCE page? You are supposed to post compilable code. Not code with mismatched braces, undeclared variables and executable code lines in the body of the class.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. how to get height of a BFS tree
    By kilyx in forum New To Java
    Replies: 1
    Last Post: 11-24-2011, 08:53 AM
  2. Width (-1) and height (-1) cannot be <= 0
    By LovJava in forum AWT / Swing
    Replies: 5
    Last Post: 04-24-2010, 01:16 AM
  3. height of the image.
    By programmer_007 in forum Java 2D
    Replies: 13
    Last Post: 02-18-2010, 01:17 PM
  4. I want set HEIGHT, WIDTH for Button
    By manhtungtnk28@gmail.com in forum AWT / Swing
    Replies: 3
    Last Post: 11-16-2009, 08:26 AM
  5. Get Image Height and Width
    By neeraj.singh in forum AWT / Swing
    Replies: 10
    Last Post: 02-18-2009, 02:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •