简体   繁体   中英

How to make swing components not resizable

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM