• Post Reply Bookmark Topic Watch Topic
  • New Topic

NullpointException with Array of javax.swing.JTextField

 
Karnati Sudhakar
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am developing an UI application and the code i am using is :



I am getting NullpointerException with this code:

ArrayofTextfields1[i] = new javax.swing.JTextField();


Can any body help me out what is the problem?

Regards
Sudhakar
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have forgotten to initialize the textfield array.
 
Karnati Sudhakar
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh,

Many thanks for your reply.if you dont mind can you help me out from an issue.The issue is i have to display those text fields on the form.How do i do it?I am using Netbeans to design UI.

Regards
Sudhakar
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you need is a layout manager.
Check out this tutorial
http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

Sorry. Can't help you with the NetBeans stuff. I use eclipse and always hand code. Never use the DND type of GUI builders.
 
Karnati Sudhakar
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maneesh,

I will go through that tutorial.is it possible to display the text fields how many we are going to display at compile time because they are calculated at runtime?

Regards
Ramesh Ale
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure it is possible.

1) Figure out how many text fields are required.
2) Create them
3) Choose your layout
4) Lay the textfields on your container
5) In the end, make your super parent (usually JFrame) visible
 
Karnati Sudhakar
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4) Lay the textfields on your container


should i use for loop here to add the components?

Regards
Sudhakar
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it's an array, how else could you do it?
 
Karnati Sudhakar
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it's an array, how else could you do it?


What i am thinking is there are some constants related to size that needs to be manipulated so i am wondering how do i do it?

Regards
Sudhakar
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A proper layout manager often helps a lot with this. You may have to try different "gap" values to separate components in the layout, such as the horizontal and vertical gaps used in a BorderLayout, but that's half the fun of using a manager: tweaking the code til it looks nice.

Originally posted by Karnati Sudhakar:


What i am thinking is there are some constants related to size that needs to be manipulated so i am wondering how do i do it?

Regards
Sudhakar
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!