How to make the text go to the panel button?

At the moment, I have the following code that works fine.

label = new JLabel(panelLabel,SwingConstants.CENTER);
outputPanel.add(label,BorderLayout.CENTER);

I get the text in the center of the panel (both in the left and in the upper bottom).

Now I want to set the position from the bottom (and in the center in terms of left-right). I tried using SOUTH instead of CENTER in the first line. The compiler does not complain, but at runtime I get IllegalArgumentException: HorizontalAlignment. What is it?

+3
source share
2 answers

The JLabel constructor you are using is JLabel(String label, int horizontalAlignement).

As defined in javadoc , this int should only be in specific values:

JLabel public JLabel ( , int horizontalAlignment)
JLabel . .

:
text - , .
horizontalAlignment - , SwingConstants: LEFT, CENTER, RIGHT, LEADING TRAILING.

, , JLabel. SOUTH, InvalidArgument.


, setVerticalAlignment (int), Swingconstants.BOTTOM, , .

BorderLayout , BorderLayout.SOUTH . , ( ). .

+5

outputPanel?

outputPanel.add(label,BorderLayout.PAGE_END);

?

outputPanel BorderLayout, . , .

+1

Source: https://habr.com/ru/post/1739167/


All Articles