• 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

BorderLayout works but only after manual resize

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was playing around with layoutmangers and threads when
I ran into this situation where what I assign to north
doesn't occupy the entire frames width. It does occuppy the entire with after I do a resize with my mouse while the program is running. Before I learn from it I wanted to check to see am I doing something wrong or this is how BorderLayour works.
Here is the code run it for yourself and see:
import java.awt.*;
import java.awt.event.*;
import java.awt.Color.*;
public class lost extends Frame {
lost () {
setLayout(new BorderLayout());
Button B = new Button();
add(B,BorderLayout.NORTH);
setBackground(Color.green);
// add(B,"south");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){System.exit(0);}
}
);
}
public static void main(String args[])
{
lost f = new lost();
f.setVisible(true);
f.setSize(600,600);
}
}
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Kourosh,
You have to set the visible property as the last statement,
after you have finished with everything in the frame.
Try this.
public static void main(String args[])
{
lost f = new lost();
f.setSize(600,600);
f.setVisible(true);
}
 
Kourosh Keshavarzi
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Devika,
I would have never thought of that.
That what's wierd about java.
You use code like setVisible and setSize that you
didn't code yourself. I'm use to procedural language
were I code everything from scratch and so I alway know exactly
what my program does and and how it does it.
Thanks again
Kourosh Keshavarzi
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic