Note that there are some explanatory texts on larger screens.

plurals
  1. POCenter JTEXTAREA Gridbag
    primarykey
    data
    text
    <p>I'm looking to center the JTextArea I have in the bottom of my swing application. I've been playing with the coordinates of the gridbag layout, but cannot seem to figure out how to extend the JTEXT AREA to fill up the space under the enter button. <img src="https://i.stack.imgur.com/xMmEg.jpg" alt="gui"></p> <pre><code>package guiprojj; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Map; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import com.json.parsers.JSONParser; import com.json.parsers.JsonParserFactory; public class gui { public static void main(String[] args) { JFrame maingui = new JFrame("Gui"); maingui.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.VERTICAL; JButton enter = new JButton("Enter"); c.gridx = 2; c.gridy = 1; maingui.add(enter, c); final JTextArea movieinfo = new JTextArea(5,20); movieinfo.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.red)); final JTextField movietext = new JTextField(18); c.gridx = 1; c.gridy = 1; maingui.add(movietext, c); final JScrollPane scrolll = new JScrollPane(movieinfo); c.gridx = 1; c.gridy = 4; maingui.add(scrolll, c); final JLabel titlee = new JLabel("Enter movie name below!"); c.gridx = 1; c.gridy = 0; maingui.add(titlee, c); maingui.setResizable(false); maingui.setVisible(true); movieinfo.setLineWrap(true); movieinfo.setWrapStyleWord(true); movieinfo.setEditable(false); scrolll.getPreferredSize(); //pangui.setPreferredSize(new Dimension(300, 150)); //pangui.add(scrolll, BorderLayout.CENTER); //movieinfo.add(scrolll); maingui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); maingui.pack(); enter.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { System.out.println(Test.getMovieInfo(movietext.getText())); JsonParserFactory factory=JsonParserFactory.getInstance(); JSONParser parser=factory.newJsonParser(); Map jsonData=parser.parseJson(Test.getMovieInfo(movietext.getText())); String Title = (String)jsonData.get("Title"); String Year = (String)jsonData.get("Year"); String Plot = (String)jsonData.get("Plot"); movieinfo.setText("Title: "+Title+"\nYear: "+ Year +"\nPlot: "+Plot); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload