tags:

views:

173

answers:

1

Hi, I'm trying to make some components inside a JSrollPane unresizable, because content inside can grow dynamically and I must prevent it from growing over a predefined size.

My approach so far is this one:

scrollPane(constraints:BL.CENTER, size:[500,200], maximumSize:[500,200]){
    panel(background:Color.WHITE, border:BF.createTitledBorder('Results')) {
        gridBagLayout()

        f0 = label(constraints:gbc(gridx:0, gridy:0))
        fk = label(constraints:gbc(gridx:0, gridy:1))

    }
 }

(this is Groovy but objects are the same as Swing (eg label = JLabel, panel = JPanel..)

And it works but when inserting into the label a text that is long for example 2000px the first call to repaint in the frame that contains this scrollpane makes the whole scrollpane resize (until the scrollbar actually disappears).

I need to force to remain to the size I want!

Am I missing something? Or is it a bug of groovy? (it seems strange because this should just maps calls to normal swing components)

+1  A: 

Why don't you just wrap the text? Anyway, Swing components have setMaximumSize(Dimension) method

Dmitry
because they are equations and wrapping them wouldn't be nice.. then I allowed also to show an image instead of text in labels so it wouldn't work. I already used maximumSize for the scrollpane :(
Jack
Cropping them would not be nice either. Anyway, what if you set maximumSize of the label?
Dmitry
Try setting scroll pane's preferredSize, by the way. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4916048
Dmitry
setMaximumSize() is not always respected by the layouts. Like recommended, check rather the preferred size.
Gnoupi
preferredSize was the way! I always used it while programming in plain Java but now I switched to Groovy too and forgot about that using just setSize and setMaximumSize.
Jack