BoxLayout 忽略 setYAlighment [英] BoxLayout ignores setYAlighment

查看:39
本文介绍了BoxLayout 忽略 setYAlighment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个函数:

/**
 * Creates an instance of a JLabel with the given arguments
 * @param text The text to be displayed on the Label
 * @param font The font of the label
 * @param bold set to true if you want the label's text to be bold
 * @param fontSize The size of the font to be rendered
 * @param alignment An alignment (E.g. CENTER_ALIGNMENT)
 * @param verticleAlignment an optional argument to allow one to choose the Y alignment
 * **/
public JLabel createLabel(String text, String font, boolean bold, int fontSize, float alignment, float...verticleAlignment){
    JLabel label = new JLabel(text);
    label.setFont(new Font(font, bold ? Font.BOLD : Font.PLAIN, fontSize));


    label.setAlignmentX(alignment);
    if(verticleAlignment.length > 0){
        label.setAlignmentY(verticleAlignment[0]);
    }
    return label;
}

出于某种原因,无论我在 varArg verticleAlignment 中输入什么,它实际上都不适用?

For some reason, no matter what I enter in the varArg verticleAlignment, it doesn't actually apply?

add(createLabel("ChatBytes™ - Do not steal.", "Arial", false, 12, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT));

谁能看出它忽略我函数的 setYAlignment 部分的原因?

Can anyone see a reason why it would ignore the setYAlignment part of my function?

推荐答案

使用

    add(Box.createVerticalGlue());

创建一个垂直空间,将组件推到 JFrame 的底部

to create a vertical space that pushes the component to the bottom of the JFrame

这篇关于BoxLayout 忽略 setYAlighment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆