简体   繁体   English

如何调整/缩放复杂的JFrame

[英]How can I resize/zoom a complex JFrame

I have a complex JFrame. 我有一个复杂的JFrame。 It has a main panel in absoluteLayout, which has buttons and labels, a couple of jFreeCharts and a second(sub) panel with a specific GridLayout, which I fill with multiple labels. 它在absoluteLayout中有一个主面板,其中包含按钮和标签,几个jFreeCharts和一个带有特定GridLayout的第二个(子)面板,我用多个标签填充。

Is there anyway to resize/zoom the whole thing? 无论如何,有没有要调整/缩放整个事情?

pack() does not work because of the layout.

Is there a more rudimentary "ScaleTheWholeWindow" approach? 有没有更基本的“ ScaleTheWholeWindow”方法?

The code for my comment would look something like this. 对我的评论的代码看起来something是这样的。 I didn't test this, this is more an idea. 我没有测试,这是一个更好的主意。 Easier to articulate my idea with code. 用代码更容易表达我的想法。

public void scaleContainer(Container c, double xFactor, double yFactor)
{
    Component[] eles = c.getComponents();
    for(int i = 0 ; i < eles.length ; i++)
    {
        eles[i].setBounds(new Rectangle(
             (int) eles[i].getX() * xFactor, 
             (int) eles[i].getY() * yFactor, 
             (int) eles[i].getWidth() * xFactor, 
             (int) eles[i].getHeight() * yFactor))
        if(eles[i] instanceof Container)
        {
            if(((Container)eles[i]).getLayout() == null) //If the container has it's own layout, let it assign it's own components
                scaleContainer((Conatiner)eles[i], xFactor, yFactor);
        }
    }
}

If you want to scale by a fixed number of pixels, and not a factor, then you need to calculate the factor. 如果要按固定数目的像素而不是因数缩放,则需要计算因数。 The factor would be 1 + (extraWidth / previousWidth) (and similar for height) 该因子将为1 + (extraWidth / previousWidth) (高度相似)

我不知道如何按照您的要求进行操作,但是更好的方法是将每个元素的宽度/高度设置为当前宽度/高度的百分比的函数,这样您将始终获得相同的结果布局,而不是您要求的基本布局。

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

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