如何使JLabel在盒子容器中正确对齐?

我有一个垂直框,我称之为父母。我添加一个JLable,然后添加一个JTextArea。Next接下来,我将创建两个分别称为right和left的垂直Box容器。Next我向它们添加2个JLable,并将这两个Box容器放入一个称为Bot的水平Box中。Bot被添加到我首先创建的父框中


这两个标签在中心彼此相邻绘制。第一个是左对齐的,第二个是右对齐的。


我希望他们两个都说对了,所以他们不会彼此相邻


Box boxParent = Box.createVerticalBox();

      String indName="test";

      String indDescription="Description";


      Box boxTitle = Box.createHorizontalBox();

      boxTitle.add(new JLabel(" Indicater:"));

      boxTitle.add(new JLabel(in    dName));

      boxParent.add(boxTitle);


      JTextArea description = new JTextArea(indDescription,5,2);

      boxParent.add(description);


      Box bot= Box.createHorizontalBox();

      Box right = Box.createVerticalBox();

      right.add(new JLabel("right"));

      right.setAlignmentX(Component.LEFT_ALIGNMENT);

      Box left = Box.createVerticalBox();

      left.setAlignmentX(Component.LEFT_ALIGNMENT);

      left.add(new JLabel("left"));

      bot.add(right);

      bot.add(left);


      boxParent.add(bot);   


翻过高山走不出你
浏览 175回答 1
1回答

HUH函数

我希望他们两个都说对了,所以他们不会彼此相邻。不确定我是否了解您的要求。他们俩都在同一行,因此无法证明自己是正确的。如果要在两个组件之间留出空间,则可能需要:  bot.add(right);   bot.add(Box.createHorizontalGlue());   bot.add(left);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java