简体   繁体   English

如何使摆动组件无法调整大小

[英]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. 我试图使JSrollPane中的某些组件无法调整大小,因为其中的内容可以动态增长,并且我必须防止其增长到预定义的大小。

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..) (这是Groovy,但是对象与Swing相同(例如,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). 它可以正常工作,但是当在标签中插入一个长例如2000px的文本时,在包含此滚动窗格的框架中的第一个重新绘制的调用将使整个滚动窗格调整大小(直到滚动条实际上​​消失)。

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) (这似乎很奇怪,因为这应该将调用映射到普通的swing组件)

Why don't you just wrap the text? 您为什么不只包装文字? Anyway, Swing components have setMaximumSize(Dimension) method 无论如何,Swing组件具有setMaximumSize(Dimension)方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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