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

  • Thread starter Thread starter uperkurk
  • Start date Start date
  • Tags Tags
    Java
Click For Summary
To position the JTextField at the bottom of the applet window, it's suggested to use a layout manager that allows for more control over component placement. The current implementation uses GridLayout, which does not support positioning components at specific locations like the bottom. Instead, utilizing a JPanel with a BorderLayout can help achieve this. By adding the JTextField to the SOUTH position of a JPanel and then adding that JPanel to the applet, the JTextField will be positioned at the bottom. Additionally, it's important to confirm whether the method is part of a JFrame or another GUI component, as this influences the layout management strategy.
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

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