So, I'm trying to make a Java/Swing GUI that looks like this:
But I'm having trouble making the search area look 'normal' ... everything blows up to fill the grid I've created there instead of looking more naturally form-like ... the code I'm using follows (let me know if there is something wrong with the code as I had to transcribe and anonymize it a bit... I know the table model is missing, but that's not the main problem... The colors are just there to show where stuff ends up within the GUI and won't be part of the final code -- think of it as print-statement debugging for GUIs :grin
I'd appreciate any suggestions!
Edit: Added the second part of the range fields.
Code:
+------------------------------------------------------------------------+
| ________________________ __________________________________________ |
| | ___________ || | |
| | Field1: |___________| || | |
| | ___________ || | |
| | Field2: |___________| || | |
| | ___________ || | |
| | Field3: |___________| || | |
| |________________________|| | |
| | Min Max || | |
| | ______ ______ || | |
| | AB: |______| |______| || TABLE DATA | |
| | ______ ______ || | |
| | BB: |______| |______| || | |
| | ______ ______ || | |
| | CB: |______| |______| || | |
| | ______ ______ || | |
| | DB: |______| |______| || | |
| |________________________|| | |
| | _______ || | |
| | |_Clear_| || | |
| |________________________||__________________________________________| |
|________________________________________________________________________|
| |
| |
| |
| |
| |
| |
| FORM-BASED DETAIL VIEW |
| |
| |
| |
| |
| |
+------------------------------------------------------------------------+
But I'm having trouble making the search area look 'normal' ... everything blows up to fill the grid I've created there instead of looking more naturally form-like ... the code I'm using follows (let me know if there is something wrong with the code as I had to transcribe and anonymize it a bit... I know the table model is missing, but that's not the main problem... The colors are just there to show where stuff ends up within the GUI and won't be part of the final code -- think of it as print-statement debugging for GUIs :grin
Code:
public class DataViewer {
public JPanel buildSearchPanel() {
JPanel upperPanel = new JPanel();
upperPanel.setLayout(new GridLayout(3, 2));
upperPanel.add(new JLabel("Field1:"));
upperPanel.add(new JTextField(5));
upperPanel.add(new JLabel("Field2:"));
upperPanel.add(new JTextField(15));
upperPanel.add(new JLabel("Field3:"));
upperPanel.add(new JTextField(15));
upperPanel.setBackground(Color.red);
JPanel rangePanel = new JPanel();
rangePanel.setLayout(new GridLayout(4,3));
rangePanel.add(new JLabel("AB:"));
rangePanel.add(new JTextField(8));
rangePanel.add(new JTextField(8));
rangePanel.add(new JLabel("BB:"));
rangePanel.add(new JTextField(8));
rangePanel.add(new JTextField(8));
rangePanel.add(new JLabel("CB:"));
rangePanel.add(new JTextField(8));
rangePanel.add(new JTextField(8));
rangePanel.add(new JLabel("DB:"));
rangePanel.add(new JTextField(8));
rangePanel.add(new JTextField(8));
JPanel buttonPanel = new JPanel();
buttonPanel.add(new JButton("Clear"));
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(upperPanel);
panel.add(rangePanel);
panel.add(buttonPanel);
return panel;
}
public JScrollPane buildDataScroller(List<Item> data) {
JTable table = new JTable(new ItemTableModel(data));
table.setAutoCreateRowSorter(true);
JScrollPane scroller = new JScrollPane(table);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroller.setBackground(Color.green);
return scroller;
}
public JPanel buildDetailPanel() {
// not yet implemented
JPanel panel = new JPanel();
panel.setBackground(Color.blue):
return panel;
}
public buildFrame() {
JFrame frame = new JFrame();
JPanel searchPanel = buildSearchPanel();
JScrollPane dataScroller = buildDataScroller();
JPanel detailPanel = buildDetailPanel();
JSplitPane innerSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, searchPanel, dataScroller);
JSplitPane outterSplitter = new JSplitPane(JSplitPane.VERTICAL_sPLIT, innerSplitter, detailPane);
frame.add(outerSplitter);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setTitle("Data Viewer");
frame.pack();
frame.setSize(800, 600);
frame.setVisible(true);
}
public void static main(String[] args) {
new DataViewer().buildFrame();
}
}
I'd appreciate any suggestions!
Edit: Added the second part of the range fields.