Trying to simple create a JList with a specified visible row count, but a minimum width. It seems "setMinimumSize()" does nothing though...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UserInterface
{
final static private int HEIGHT = 400;
final static private int WIDTH = 650;
public static void main(String[] args) {
JPanel content = new JPanel();
String[] entries = { "Entry 1", "Entry 2", "Entry 3",
"Entry 4", "Entry 5", "Entry 6" };
DefaultListModel sampleModel = new DefaultListModel();
for(int i=0; i<entries.length; i++)
sampleModel.addElement(entries[i]);
JList sampleList = new JList(sampleModel);
sampleList.setMinimumSize(new Dimension(1000,1000));
sampleList.setMaximumSize(new Dimension(1000,1000));
content.add(sampleList);
//main window frame
JFrame window = new JFrame("NAD Assignment 1");
window.setSize(WIDTH, HEIGHT);
window.setContentPane(content);
window.setLocationRelativeTo(null);
window.setVisible(true);
window.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
setPreferredSize() seems to work, but it overrides whatever I set up in setVisibleRowCount():
public static void main(String[] args) {
JPanel content = new JPanel();
String[] entries = { "Entry 1", "Entry 2", "Entry 3",
"Entry 4", "Entry 5", "Entry 6" };
DefaultListModel sampleModel = new DefaultListModel();
for(int i=0; i<entries.length; i++)
sampleModel.addElement(entries[i]);
JList sampleList = new JList(sampleModel);
sampleList.setPreferredSize(new Dimension(200,10));
sampleList.setVisibleRowCount(8);
content.add(sampleList);
//main window frame
JFrame window = new JFrame("NAD Assignment 1");
window.setSize(WIDTH, HEIGHT);
window.setContentPane(content);
window.setLocationRelativeTo(null);
window.setVisible(true);
window.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
How can I set a minimum width on my JList and specify the height with setVisibleRowCount? Thanks.