2

I have a JScrollPane which has a JList inside;

    instructionsScrollPane = new JScrollPane(instructionList);

The JScrollPane is itself in a JPanel using BorderLayout;

    panel.add(instructionsScrollPane, BorderLayout.WEST);

Now, I am trying to stop the list/scrollpane going below a a certain minimum size when the window is resized, except JScrollPane can't have minimum size set, and the list is inside the JScrollPane which can't have a layoutManager. So I am unable to set the minimum size of the JList without a layoutManager...

Now, I think I could have the JScrollPane/JList centered using BorderLayout inside another JPanel (which I would then set a minimum size of) inside this the current panel... but that seems messy. Does anyone know of a better way to size ScrollPanes?

I know there is probably a solution using a different layoutManager, but I am already committed to using BorderLayout at this point.

Rudi Kershaw
  • 12,332
  • 7
  • 52
  • 77
  • 1
    don't commit to a _specific_ LayoutManager (at least not to such a poor beast as BorderLayout) - learn about what each has to offer and choose one that fits your requirements best. – kleopatra Aug 20 '13 at 11:31

1 Answers1

4

Now, I could have the JScrollPane centered using BorderLayout inside another JPanel (which I would set a minimum size of) inside this the current panel... but that seems messy. Does anyone know of a better way to size ScrollPanes?

for JList is very easy, simple to set initial coordinates, returns expected Dimension for LayoutManager, there are two methods implemented in API

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • What's the advantage of using setPrototypeCellValue over using setFixedCellWidth? I'm having a little difficulty understand exactly how setPrototypeCellValue works. – Rudi Kershaw Aug 20 '13 at 11:04
  • setPrototypeCellValue(see top of JList API) is used for example, now I'll talking about String instance only, but is applicable to all data types, you can to compute the longest String lenght before (XxxwwwAAA111eee), then put this value as setPrototypeCellValue(" XxxwwwAAA111eee ") – mKorbel Aug 20 '13 at 11:10
  • Thanks! Looks as though I will be using `setFixedCellWidth()` in the end because a lot of the entries in the list will be very long indeed, and I need to to line up quite precisely with a couple other components. – Rudi Kershaw Aug 20 '13 at 11:52
  • `because a lot of the entries in the list will be very long indeed` == [wait, stop, you are going to impasse, make things simpler, otherwise you are prisonier of your ****, you would need to ....](http://stackoverflow.com/a/12867849/714968) – mKorbel Aug 20 '13 at 11:57
  • Ah, yes. Thanks for pointing that out. I will cut short the visible strings before I attach them to the list. – Rudi Kershaw Aug 20 '13 at 12:01