I need some help with the code below. What I'm trying to do is to expand the size of TextArea (named preview
) to include the last three buttons: algo1
, algo2
and algo3
.
I have tried many times to change the code but it still only shows one button, which is algo1
, and not all three buttons. Has it got something to do with the BASELINE
or LEADING
? Can someone please show where I have gone wrong? Thanks.
import java.awt.*;
import javax.swing.*;
// Create a simple GUI window
public class win {
private static void createWindow() {
//Create and set up the window.
JFrame frame = new JFrame("PDF Denoiser");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//My edit
JPanel panel = new JPanel();
GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
JLabel label1 = new JLabel("Image File");
JLabel label2 = new JLabel("Destination");
JLabel label3 = new JLabel("Preview");
JTextField current = new JTextField();
JTextField dest = new JTextField();
JTextArea preview = new JTextArea();
JButton choose1 = new JButton("Search1");
JButton choose2 = new JButton("Search2");
JButton algo1 = new JButton("MDWM");
JButton algo2 = new JButton("BFMR");
JButton algo3 = new JButton("Mine");
//Horizontal arrangement
layout.setHorizontalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(label1)
.addComponent(label2)
.addComponent(label3))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(current)
.addComponent(dest)
.addComponent(preview))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(choose1)
.addComponent(choose2)
.addComponent(algo1)
.addComponent(algo2)
.addComponent(algo3))
);
layout.linkSize(SwingConstants.HORIZONTAL, choose1, choose2, algo1, algo2, algo3);
//Vertical arrangement
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label1)
.addComponent(current)
.addComponent(choose1))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label2)
.addComponent(dest)
.addComponent(choose2))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(label3)
.addComponent(preview)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(algo1)
.addComponent(algo2)
.addComponent(algo3))))
);
//Display the window.
frame.setLocationRelativeTo(null);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
createWindow();
}
}