2
How to create a Jframe, containing a Jlabel with text, and can be positioned anywhere in the frame.
I need this label to be anywhere in the frame area.
2
How to create a Jframe, containing a Jlabel with text, and can be positioned anywhere in the frame.
I need this label to be anywhere in the frame area.
3
package teste02;
import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TelaSistema extends JFrame
{
public TelaSistema()
{
setSize(600, 400);
setTitle("Sistema ");
JPanel painel = new JPanel();
painel.setLayout(null);
JLabel label = new JLabel();
label = new JLabel("Olá mundo !");
painel.add(label);
label.setBounds(250, 150, 300, 50);
add(painel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
TelaSistema teste = new TelaSistema();
}
}
Browser other questions tagged java swing jframe
You are not signed in. Login or sign up in order to post.
Give a sought before posting the questions, It may be that have already been put here.
– Gustavo Santos
can leave, it is that I am new here, but thanks! Thank you, I will test the Cod.
– user59450
can change label text color ?
– user59450
@Javinha does. A very simple way is to implement HTML tags. Example: <html>The <font color=#3061AB field> text here </font> </html>
– Gustavo Santos
Why use html if jlabel has native resource? Another thing, one should avoid using absolute position, unless this is of extreme necessity, this makes the screen construction and addition of components highly complex, so there are layoutmanagers, to do the "heavy work" of positioning for us.
– user28595
jLabel1.setForeground(Color.red);
for example, this way changes to red. See more colors in documentation of the Color class– user28595
Thanks guys, I tested both ways for colors. HTML solved better, due to the amount of words I edited within the text, and as for positioning, it was extremely necessary. Thanks again !
– user59450