jlabel

How to add JLabel at run time in Swing?

蓝咒 提交于 2020-07-20 01:17:50
问题 I am making am window application on Java. I want to add label name at run time in my Swing application. How can I do this using Java Swing? public class Component1 extends JPanel { Component1() { JLabel label = new JLabel("dd"); label.setBounds(370, 340, 150, 20); // label.setText("labeVVl"); add(label); } public static void main(String[] args) { // create frame JFrame frame = new JFrame(); final int FRAME_WIDTH = 800; final int FRAME_HEIGHT = 600; // set frame attributes frame.setSize(FRAME

How to loop text of an element in JLabel?

老子叫甜甜 提交于 2020-06-27 04:07:16
问题 I'm having a problem with loops. How does this loop, loop through different values ​​and display all values ​​on the label, rather than displaying the last value of the array on the label? Image of code for loop. 回答1: This below code is just copied(written) from your screenshot. which has the minor bug. sinhvien sv = new sinhvien(); sv.setdata("CC",12); sv.setdata("CL",14); sv.setdata("CCCL",16); s1.add(sv); As you have only created one instance of sv and setting the value 3 times. Value CCCL

Delete Text from JLabel after 5 seconds?

流过昼夜 提交于 2020-06-25 07:15:32
问题 I wanted to know if there's any easy way to delete the content (text) from a JLabel after 5 seconds. Is that possible? Because I have a JLabel in a JFrame and it shows some internal errors from the program I'm coding and I want the JLabel to show the message for a couple of seconds and then go to blank. Any ideas? 回答1: Simplest solution is to use a Swing Timer. It will prevent freezing the GUI and ensure proper Thread access (ie, UI modification is performed on the EDT). Small demo example:

How to make ImageIcon on JLabel update faster with less latency

痴心易碎 提交于 2020-05-30 08:13:09
问题 I am trying to update an ImageIcon on a JLabel which sits on a JLayeredPane, but there is a lot of latency between when the setting thread sends the proper state to the JLabel object and when the GUI displays the ImageIcon of the proper state. The following code is an example of the issue, look for the difference in time between the print of the button being on/off and when the displayed icon gets lighter/darker. The setting thread: new Thread(new Runnable() { // setting thread @Override

How to make ImageIcon on JLabel update faster with less latency

偶尔善良 提交于 2020-05-30 08:13:02
问题 I am trying to update an ImageIcon on a JLabel which sits on a JLayeredPane, but there is a lot of latency between when the setting thread sends the proper state to the JLabel object and when the GUI displays the ImageIcon of the proper state. The following code is an example of the issue, look for the difference in time between the print of the button being on/off and when the displayed icon gets lighter/darker. The setting thread: new Thread(new Runnable() { // setting thread @Override

Java: Invalid Character Constant error occurring

本小妞迷上赌 提交于 2020-05-18 08:32:22
问题 I'm try to make a notification. I saw a little tutorial but something is not working for me. JLabel messageLabel = new JLabel('<HtMl>'+message); "Invalid Character Constant" Why is this error occurring? 回答1: You need double quotes the single quotes is for char literals. JLabel messageLabel = new JLabel("<HtMl>"+message); or JLabel messageLabel = new JLabel('l'+message); 回答2: You should use double quotes instead of single quotes to resolve your problem. 来源: https://stackoverflow.com/questions

Java: Invalid Character Constant error occurring

亡梦爱人 提交于 2020-05-18 08:31:11
问题 I'm try to make a notification. I saw a little tutorial but something is not working for me. JLabel messageLabel = new JLabel('<HtMl>'+message); "Invalid Character Constant" Why is this error occurring? 回答1: You need double quotes the single quotes is for char literals. JLabel messageLabel = new JLabel("<HtMl>"+message); or JLabel messageLabel = new JLabel('l'+message); 回答2: You should use double quotes instead of single quotes to resolve your problem. 来源: https://stackoverflow.com/questions