• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Textbox missing from Application  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi guys so i have an issue with this program as the textbox to add information is missing. When i run the application , the whitebox to add information is missing.  I know there is a simple fix but i just cant see it at the moment . Any help will be greatly appreciated
 
Marshal
Posts: 61691
193
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you declaring the text box (line number, please)?
How are you adding it to the top‑level container (again, line number, please)? What layout does the container you are adding it to have? If border layout, are you adding anything else to that container? If flow layout, what are the sizes of the container and its child components? I don't like flow layout because of its propensity to change alignments when resized and because components can vanish if the container shrinks.
 
Yogi Permaul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Where are you declaring the text box (line number, please)?
How are you adding it to the top‑level container (again, line number, please)? What layout does the container you are adding it to have? If border layout, are you adding anything else to that container? If flow layout, what are the sizes of the container and its child components? I don't like flow layout because of its propensity to change alignments when resized and because components can vanish if the container shrinks.



I added my JLabels and textboxes from Line 25 to 32. The rows are set out in flow layout(4,20). I've added the Jtextfields so i'm terribly confused as to why the textbook does not appear when i run the application.
 
Bartender
Posts: 9491
184
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, the fix is quite simple. You have four text fields (name, id, transfer and course) and you never actually add them to any of your containers.

A few other things you should look out for:

  • Make your fields private and final.
  • Give your classes and methods proper names. 'Transfer' doesn't communicate that it is part of the user interface. Instead, call it 'TransferForm'.
  • Don't let forms extend JFrame. Instead, use a JFrame as a private final field.
  • Don't let forms implement ActionListener. Instead, create a field of type Action for each action your form can perform (don't use action commands), and assign to it an anonymous implementation of AbstractAction. Instantiate buttons with actions.
  • Don't call System.exit(0) from your WindowAdapter. This prevents processes from terminating normally. Just call dispose() on the JFrame.
  • Perform all UI operations on the Event Dispatch Thread. From the main() method, you can do this by calling SwingUtilities.invokeLater().
  •  
    Campbell Ritchie
    Marshal
    Posts: 61691
    193
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Yogi Permaul wrote:. . . I added my JLabels and textboxes from Line 25 to 32. . . .

    No, you simply declared them there. As Stephan said, you must write xxx.add(myTextField); beofe they will appear. And they aren't text boxes; they are text fields, which are different. There is more informaton in the Java Tutorials.
     
    Yogi Permaul
    Greenhorn
    Posts: 26
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for pointing me in the right direction guys. It was a stupid thing to overlook , beginner problems . I managed to correct my mistake and got the application to work perfectly.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!