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 :
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
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
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.
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 ?
Re: status bar - its height is changed while resizing window.But Height must be same.
Forum Rules
http://www.java-forums.org/forum-gui...w-members.html
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