I have actually made a small test program which shows my problem:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.DefaultListModel;
import javax.swing.JToolBar;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import javax.swing.JList;
public class Test extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test frame = new Test();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private static final Dimension MAX_WIDTH_256 = new Dimension(256, Integer.MAX_VALUE);
public Test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
JPanel contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JToolBar toolBar = new JToolBar();
toolBar.setMaximumSize(MAX_WIDTH_256);
contentPane.add(toolBar, BorderLayout.EAST);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setMaximumSize(MAX_WIDTH_256);
toolBar.add(tabbedPane);
JPanel tab = new JPanel();
tab.setLayout(new BorderLayout(0, 0));
tab.setMaximumSize(MAX_WIDTH_256);
tabbedPane.addTab("Some Strings", null, tab, null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setMaximumSize(MAX_WIDTH_256);
tab.add(scrollPane, BorderLayout.CENTER);
DefaultListModel<String> listModel = new DefaultListModel<String>();
for (String str : new String[] {
"Small",
"Bigger",
"Even Bigger",
"Already quite Big",
"This one is really really big, it has an insane size and showing it in a list would be a really stupid idea!",
}) {
listModel.addElement(str);
}
JList<String> list = new JList<>();
list.setMaximumSize(MAX_WIDTH_256);
list.setModel(listModel);
scrollPane.setViewportView(list);
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
contentPane.add(panel, BorderLayout.CENTER);
}
}
If anybody could make the toolbar accept its maximum size I would really appreciate.