Thanks for the suggestions, Cornix. I ended up just using GridBagLayout to put everything on one panel. However, I'm having trouble getting my arrow buttons to position themselves correctly and be the correct size. I'll post my code below:
package manager;
import javax.swing.SwingUtilities;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Gui();
}
});
}
}
package manager;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;
import javax.swing.plaf.basic.BasicArrowButton;
public class Gui extends JFrame {
private GridBagConstraints constraints;
private JButton burnButton, leftArrowButton, rightArrowButton;
private JPanel panel;
private JScrollPane localFilesScrollPane, mediaFilesScrollPane;
private JTextPane localFilesTextPane, mediaFilesTextPane;
private JMenuBar menu;
private JMenu file, edit;
private JMenuItem exit;
public Gui() {
initComponents();
setVisible(true);
}
private void initComponents() {
constraints = new GridBagConstraints();
burnButton = new JButton("Burn");
leftArrowButton = new BasicArrowButton(BasicArrowButton.WEST);
rightArrowButton = new BasicArrowButton(BasicArrowButton.EAST);
panel = new JPanel();
localFilesScrollPane = new JScrollPane();
mediaFilesScrollPane = new JScrollPane();
localFilesTextPane = new JTextPane();
mediaFilesTextPane = new JTextPane();
menu = new JMenuBar();
file = new JMenu("File");
edit = new JMenu("Edit");
exit = new JMenuItem("Exit");
menu.add(file);
menu.add(edit);
file.add(exit);
panel.setLayout(new GridBagLayout());
setJMenuBar(menu);
localFilesTextPane.setEditable(false);
mediaFilesTextPane.setEditable(false);
localFilesScrollPane.setViewportView(localFilesTextPane);
mediaFilesScrollPane.setViewportView(mediaFilesTextPane);
localFilesScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder(BorderFactory.createLineBorder(Color.black), "Local Files"),
BorderFactory.createEmptyBorder(10, 15, 10, 15)));
mediaFilesScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder(BorderFactory.createLineBorder(Color.black), "Files on Media"),
BorderFactory.createEmptyBorder(10, 15, 10, 15)));
setSize(1000, 500);
setTitle("Java Burner");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLocationRelativeTo(this);
localFilesScrollPane.setPreferredSize(new Dimension(400, 300));
mediaFilesScrollPane.setPreferredSize(new Dimension(400, 300));
constraints.insets = new Insets(15, 15, 15, 15);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridheight = 2;
panel.add(localFilesScrollPane, constraints);
constraints.gridx++;
constraints.gridheight = 1;
panel.add(leftArrowButton, constraints);
constraints.gridx++;
constraints.gridheight = 2;
panel.add(mediaFilesScrollPane, constraints);
constraints.gridx--;
constraints.gridy++;
constraints.gridheight = 1;
panel.add(rightArrowButton, constraints);
constraints.gridx++;
constraints.gridy++;
constraints.anchor = GridBagConstraints.SOUTHEAST;
panel.add(burnButton, constraints);
add(panel, BorderLayout.CENTER);
}
}
If you take a look at it, you'll see that the arrow buttons in the middle of the text panes are way too small. They need to be larger. I also need the top arrow button moved down a little and the bottom arrow button moved up. When I tell the buttons to fill their respective cells, the bottom button fills a large amount of space while the top button doesn't change. I'm not sure how to resize the cells. I would appreciate any help.
--- Update ---
So I wasn't able to get the buttons to cooperate on the GridBagLayout, so I created a new panel with a BoxLayout to place the buttons in. It seems to be working better, but I still can't get the buttons to resize properly. Calling setPreferredSize() on the arrow buttons does nothing.
This is my new code:
package manager;
import javax.swing.SwingUtilities;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Gui();
}
});
}
}
package manager;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;
import javax.swing.plaf.basic.BasicArrowButton;
public class Gui extends JFrame {
private GridBagConstraints constraints;
private JButton burnButton, leftArrowButton, rightArrowButton;
private JPanel mainPanel, buttonPanel;
private JScrollPane localFilesScrollPane, mediaFilesScrollPane;
private JTextPane localFilesTextPane, mediaFilesTextPane;
private JMenuBar menu;
private JMenu file, edit;
private JMenuItem exit;
public Gui() {
initComponents();
setVisible(true);
}
private void initComponents() {
constraints = new GridBagConstraints();
burnButton = new JButton("Burn");
leftArrowButton = new BasicArrowButton(BasicArrowButton.WEST);
rightArrowButton = new BasicArrowButton(BasicArrowButton.EAST);
mainPanel = new JPanel();
buttonPanel = new JPanel();
localFilesScrollPane = new JScrollPane();
mediaFilesScrollPane = new JScrollPane();
localFilesTextPane = new JTextPane();
mediaFilesTextPane = new JTextPane();
menu = new JMenuBar();
file = new JMenu("File");
edit = new JMenu("Edit");
exit = new JMenuItem("Exit");
menu.add(file);
menu.add(edit);
file.add(exit);
mainPanel.setLayout(new GridBagLayout());
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
setJMenuBar(menu);
localFilesTextPane.setEditable(false);
mediaFilesTextPane.setEditable(false);
localFilesScrollPane.setViewportView(localFilesTextPane);
mediaFilesScrollPane.setViewportView(mediaFilesTextPane);
localFilesScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder(BorderFactory.createLineBorder(Color.black), "Local Files"),
BorderFactory.createEmptyBorder(10, 15, 10, 15)));
mediaFilesScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder(BorderFactory.createLineBorder(Color.black), "Files on Media"),
BorderFactory.createEmptyBorder(10, 15, 10, 15)));
setSize(1000, 450);
setTitle("Java Burner");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLocationRelativeTo(this);
localFilesScrollPane.setPreferredSize(new Dimension(400, 300));
mediaFilesScrollPane.setPreferredSize(new Dimension(400, 300));
buttonPanel.add(Box.createVerticalStrut(80));
buttonPanel.add(leftArrowButton);
buttonPanel.add(Box.createVerticalStrut(80));
buttonPanel.add(rightArrowButton);
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridheight = 2;
constraints.insets = new Insets(0, 0, 0, 20);
mainPanel.add(localFilesScrollPane, constraints);
constraints.gridx++;
constraints.insets = new Insets(0, 20, 0, 0);
mainPanel.add(buttonPanel);
constraints.gridx++;
constraints.gridheight = 2;
mainPanel.add(mediaFilesScrollPane, constraints);
constraints.gridy = 2;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.SOUTHEAST;
constraints.insets = new Insets(20, 5, 10, 5);
mainPanel.add(burnButton, constraints);
add(mainPanel, BorderLayout.CENTER);
}
}
This is very close to what I want. I just need to make the arrow buttons larger. Any help?