Java GridLayout for Applet Window: Add, Display, Search, and Remove Words

  • Context: Java 
  • Thread starter Thread starter uperkurk
  • Start date Start date
  • Tags Tags
    Java
Click For Summary
SUMMARY

The discussion focuses on using Java's GridLayout to arrange components in an applet window, specifically addressing the placement of a JTextField at the bottom. The provided code snippet initializes a GridLayout with six rows and multiple buttons for adding, displaying, searching, and removing words. To position the JTextField correctly, it is suggested to utilize JPanel(s) for better control over component placement, particularly if the method is part of a JFrame extension.

PREREQUISITES
  • Java programming knowledge, specifically with applets and GUI components
  • Understanding of GridLayout and its parameters in Java
  • Familiarity with JPanel for component organization
  • Basic knowledge of event handling in Java using ActionListener
NEXT STEPS
  • Explore Java Swing layout managers, focusing on JPanel and its use with GridLayout
  • Learn about Java ActionListener implementation for handling button clicks
  • Investigate alternative layout managers like BorderLayout and FlowLayout for different UI designs
  • Study best practices for organizing GUI components in Java applications
USEFUL FOR

Java developers, particularly those working with applets and GUI design, as well as anyone looking to enhance their skills in component layout management within Java applications.

uperkurk
Messages
167
Reaction score
0
Can anyone tell me how to get the Textbox to the bottom of the applet window?
Code:
public void init(){
        setLayout(new GridLayout(6,0,5,5));
        al = new ArrayList();
        addNewWords = new JButton("Add Word");
        displayAllWords = new JButton("Display Words");
        searchForWords = new JButton("Search List");
        removeWords = new JButton("Delete Word");
        removeDuplicates = new JButton("Delete Duplicates");
        removeAllWords = new JButton("Delete all words");
        addNewWords.addActionListener(new ButtonHandlerForAddWord(this));
        newWordTextField = new JTextField("Enter a word", 20);
        add(addNewWords);
        add(displayAllWords);
        add(searchForWords);
        add(removeWords);
        add(removeDuplicates);
        add(removeAllWords);
        add(newWordTextField, BorderLayout.SOUTH);
    }
 
Technology news on Phys.org
uperkurk said:
Can anyone tell me how to get the Textbox to the bottom of the applet window?
Code:
public void init(){
        setLayout(new GridLayout(6,0,5,5));
        al = new ArrayList();
        addNewWords = new JButton("Add Word");
        displayAllWords = new JButton("Display Words");
        searchForWords = new JButton("Search List");
        removeWords = new JButton("Delete Word");
        removeDuplicates = new JButton("Delete Duplicates");
        removeAllWords = new JButton("Delete all words");
        addNewWords.addActionListener(new ButtonHandlerForAddWord(this));
        newWordTextField = new JTextField("Enter a word", 20);
        add(addNewWords);
        add(displayAllWords);
        add(searchForWords);
        add(removeWords);
        add(removeDuplicates);
        add(removeAllWords);
        add(newWordTextField, BorderLayout.SOUTH);
    }

Is this method in an extension of a JFrame or other GUI object? If it is a JFrame, you'll want to use JPanel(s) to control the relative positioning of elements.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
13K