Hey Guys I am programming a calculator with buttons and have a separate class "Operators" for the "brain behind the buttons" (as bucky would say).
So Now when I press the Buttons they execute the Operators(int nr) method in the Operators class, which is working since the console prints out the number of the button pressed, but it does not change the text of Label1.
Typically, the label's painting area is exactly the size needed to paint on the label and thus label alignment is irrelevant.
For more information about X and Y alignment, see How to Use Box Layout.
In our introduction to threading with Swing, we said that any updates to the user interface must happen on the event dispatch thread.
By specifying HTML code in a label's text, you can give the label various characteristics such as multiple lines, multiple fonts or multiple colors. If you need to paint the label's background, it is recommended that you turn its opacity property to "true". Image Icon icon = create Image Icon("images/middle.gif"); . CENTER); //Set the position of the text, relative to the icon: label1Vertical Text Position(JLabel. CENTER); label2 = new JLabel("Text-Only Label"); label3 = new JLabel(icon); method is similar to that used throughout this tutorial. X and Y alignment are used by layout managers and can affect the way any component not just a label is sized or positioned.The thoughts behind my code is that in the Operators(int nr) method the method Label1(nr); gets called, which is in the class and has the code label1Text(txt);. Here is the full code: Hmm wait I just noticed a problem.So theoretically it should change the text of Label1. If I do it like that it will always place the Number of the Button I clicked in Label1.In this article, I’ll show you how you can get your programs working even if you’re using the Thread class, and then we’ll go on to look at the Swing Worker solution. For demonstration purposes, I’ve created a little Swing program.