I have a following code :
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Main extends JPanel implements ActionListener {
protected JTextArea output;
protected JTextField fileInput, dateInput;
protected JPanel topBar, bottomBar, centerPanel;
protected JButton load, sortName, sortNSD, sortDate, show;
public Main() {
super(new BorderLayout());
topBar = new JPanel(new FlowLayout());
centerPanel = new JPanel();
bottomBar = new JPanel(new FlowLayout());
this.add(topBar, BorderLayout.NORTH);
this.add(centerPanel, BorderLayout.CENTER);
this.add(bottomBar, BorderLayout.SOUTH);
load = new JButton("Load");
sortName = new JButton("Sort by Name");
sortNSD = new JButton("Sort by N,S,D");
sortDate = new JButton("Sort by Date");
show = new JButton("Show");
output = new JTextArea(5, 40);
fileInput = new JTextField(25);
dateInput = new JTextField(8);
output.setEditable(false);
JScrollPane scroller = new JScrollPane(output);
Label outputLabel = new Label("Output:");
topBar.add(sortName);
topBar.add(sortNSD);
topBar.add(sortDate);
topBar.add(dateInput);
topBar.add(show);
centerPanel.add(scroller);
bottomBar.add(fileInput);
bottomBar.add(load);
}
public void actionPerformed(ActionEvent evt) {
}
private static void createWindow() {
JFrame frame = new JFrame("Zd2_1");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new Main());
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createWindow();
}
});
}
}
which gives me this output : http://img202.imageshack.us/img202/7359/92250063.gif . How can I improve my layout to :
- look more pro (introduce borders around buttons ?)
- keep constant size
- how do you add the label ?
I'm not too good at layouts :/
EDIT
Found hov to bleck the size :
frame.setResizable(false);
frame.setSize(330, 480);