I'm a new in Swing. I'm trying to create a window 800x600 that will be divided into two equal parts (800x300): first one a immutable text-area and the second - button.
Problem: Button should occupy the bottom half of the window. But seems button size doesn't work correct.
Code:
import javax.swing.*;
import javax.xml.parsers.ParserConfigurationException;
import java.awt.*;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main {
public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
JFrame.setDefaultLookAndFeelDecorated(true);
final JFrame frame = new JFrame("Lingvo frame");
frame.setPreferredSize(new Dimension(800, 600));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(4,4,4,4));
final JButton showResultButton = new JButton();
showResultButton.setPreferredSize(new Dimension(800, 300));
showResultButton.setHorizontalAlignment(SwingConstants.CENTER);
showResultButton.setVerticalAlignment(SwingConstants.BOTTOM);
frame.add(panel);
panel.add(showResultButton);
frame.pack();
frame.setVisible(true);
showResultButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
showResultButton.setText("translation");
}
});
}
}