File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes labels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "labels" Watch "labels" New topic


josephine chen
Ranch Hand

Joined: Oct 29, 2002
Posts: 216
import java.awt.*;
import java.awt.event.*;
class btnev extends Button implements ActionListener{
static Frame w = new Frame();;
static btnev bt = new btnev();
static Label l = new Label();
void addframe(){
public static void main(String s[]){
Button b = new Button("ok");
bt.w.setLayout(new FlowLayout());
w.setLayout(new FlowLayout(FlowLayout.CENTER));
public void actionPerformed(ActionEvent e){
if ((l.getText())== "hello")


I am able to display the label but i want the label to be in the center of the frame but it always aligns near the button.How to
get it to the center of the frame???
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
You will need to use some layout manager other than FlowLayout, which will always try to put components next to each other unless they simply won't fit on a line. The simplest alternative is probably BorderLayout. Add the OK button to the North region, and add the label to the Center region. If that's not what you want, you may also want to look at BoxLayout or GridBagLayout, which are more powerful and more complicated (especially GridBagLayout - it can do mast anything you want, but it's hardest to learn.) Spend some time learning about each layout - they each have their own special tricks.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: labels
jQuery in Action, 3rd edition