Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting a JScrollPane to display its scrollbars

 
chinomso ikwuagwu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public Object [] showDeleteTableOptions() {
Vector listData = getListData();// This retrieves a vector containing the options
listData.trimToSize();
int size = listData.size();

JCheckBox [] checkBoxes = new JCheckBox[size];

JPanel panel = new JPanel();
panel.setLayout(new GridLayout(size, 1));

for (int i=0; i< size; i++) {
checkBoxes[i] = new JCheckBox(listData.get(i).toString());
panel.add(checkBoxes[i]);
}
int dialogResult = JOptionPane.showOptionDialog(this, new JScrollPane(panel), " Select table(s) to delete",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, okAllCancel, okAllCancel[0]);

if (dialogResult ==0 ) {// Process...}
}

Question. Why doesn't the JScrollPane's scrollbar show when the panel contains a large list which is almost the height of the screen.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing forum...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
run this as is, then comment out the indicated line, and uncomment the block
run it again, then uncomment the preferredSize() line, and run it again

 
chinomso ikwuagwu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Learnt something new.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic