This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown


Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 think I'll just lie down here for a second. And ponder this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic