Questions tagged [jlabel]

A Java Swing component to display a short text string or an image, or both.

A JLabel object can display either text, an image, or both. You can specify where in the label's display area the label's contents are aligned by setting the vertical and horizontal alignment. By default, labels are vertically centered in their display area. Text-only labels are leading edge aligned, by default; image-only labels are horizontally centered, by default.

Unlike text fields and many other controls, JLabels are transparent by default: parent content is visible in places not covered by text and icon, and setting the background colour has no effect. JLabel can be made opaque by setOpaque(true).

Reference: Class JLabel

3264 questions
0
votes
0 answers

How to make KeyBinded labels not be able to leave the JFrame (For a game)

I have 4 different classes of Code, but I had a problem with the main game part. Basically, as a cube you move around to get to a specific area, but for some reason using keybound labels it allows the label to leave the frame and basically…
0
votes
1 answer

How to hide some text if there is no space in JLabel?

I have some long text in a JLabel e.g. "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua". I want to hide some text if the user resizes the window and there is no much space.…
dragon7
  • 1,057
  • 9
  • 23
0
votes
0 answers

Why does JLabel convert any nuber in a string to "..." in Java?

I tried: //All the stuff with JLabel initialization int Number = 10; String data = "Value: " + Number; lbl.setText(data); //The JLabel says: "Value:..." System.out.println(data); //The console says: "Value: 10" How can I fix this? This problem…
0
votes
1 answer

JLabel text shadow

I have a JLabel with text. The text displays in different colors and since I also want the background to change color, I found sometimes the text it's hard to read. That is why I want to add a shadow to the font like this: React Native font outline…
GalliadII
  • 162
  • 1
  • 14
0
votes
1 answer

How to use a JLabel as a JButton?

I am trying to make a program that uses a JButton, but the regular button isn't working, so I want to make it so that when I press the JLabel it will activate a function.
0
votes
1 answer

Horizontally scrolling text in a JPanel or JTextField (like news bar in TV)

Can anybody give me some advice on how can I do that? I found some code on the internet but I don't know how to use it how to add it to my code and use it since that code creates a frame on its own. How can I assign a JLabel to this code? Here is…
0
votes
0 answers

How can I avoid components shadow going top of each other in JFrame?

When I changing the dark mode check box, it's shadow goes behind the dateLabel. How can I avoid this? with shadow if (isDarker) { dateLabel.setForeground(new java.awt.Color(255, 0, 51)); wallpaper.setIcon(new…
Some One
  • 103
  • 1
  • 1
  • 5
0
votes
1 answer

How do I move around objects in JFrame?

I have been working on building a simple game using JFrame, JLabel, and buttons to execute different commands. However, the problem that I have been encountering is that I am unable to move around items in the JFrame no matter what I do. I am doing…
0
votes
3 answers

Java: Load image from file, edit and add to JPanel

I want to load an image from my computer into 2D Graphics so that I can edit it afterwards and then I want to add it to JPanel. If you need to see my project I can send it to you. void loadImage() { FileDialog fd = new FileDialog(new Frame(),…
0
votes
1 answer

How to open new window by clicking label in java?

I want to open a new window when I click the label. By implementing a key pressed listener. But it is not working. Even nothing is happening. JLabel lblNewLabel_2 = new JLabel("Create New…
Mr.Roy
  • 35
  • 1
  • 2
  • 8
0
votes
0 answers

IntelliJ 2019 - Image shows when I "Run Gui" but not when I execute the jar

I haven't yet found an answer to this in any other posts. Most give the same instructions but none have worked. I am using the Swing Designer in IntelliJ. My resource file is marked as a Resource file. When I click the Run Gui button the window…
Eddie T
  • 101
  • 5
0
votes
1 answer

Java - ImageIcon not reloading an update file

I have a file loading wizard as part of my Java application, allowing the user to add images to a room. Using common image editing software the user saves the .gif file to a specified folder that my application accesses to load the .gif file as a…
0
votes
0 answers

How to display an added player's details on a JPanel?

I have a method that adds a player to my game. After clicking the "Add Player" button, I want the player's chosen avatar, name, points, and current bet total to be displayed on a JPanel. Previously added players should also be displayed on the…
Wolfizzy
  • 581
  • 1
  • 4
  • 18
0
votes
1 answer

Alternative solution on randomizing JLabel

So, I have this task where the user guess the correct number just by clicking on the JLabel I have presented for them. What I was trying to is to generate a random number then use if (e.getSource() == random) { } but it seems object and int isn't a…
Testtest
  • 23
  • 5
0
votes
3 answers

Updating variables inside labels

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TestSwingListeners1 { private static int cnt1; private static int cnt2; public static void main(String[] args) { JFrame fr1 = new JFrame("Swing…
Haroyee
  • 11
  • 5
1 2 3
99
100