• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jlabel creation problem. Do guide  RSS feed

 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


"Id" overlaps the "name"
what is the reason and y we need to add Contentpane()??

output required:
name
id

But is dispalys only id
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't you need to set the layout?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem here is that default content pane of a JFrame uses BorderLayout.
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle is right. That means that if you just call add without any constraints, the component will be put in the center (as if BorderLayout.CENTER was used). However, BorderLayout only supports one component at each location. You'll need to add the components with explicit constraints, like BorderLayout.NORTH for the first and BorderLayout.CENTER for the second.


veena joshi wrote:y we need to add Contentpane()??

1) Please UseRealWords: "why", not "y".
2) That was necessary in Java 1.4 and before. Since Java 5.0 you can simply add to the JFrame; it delegates the calls to add, remove, removeAll and setLayout to its content pane.
 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


ITS WORKING!!! thank you all!!





its working fine. is there any better option to modularize the code??
Kindly suggest.
Thanks to all.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!