jlabel

How to change a JLabel text for x Seconds

╄→гoц情女王★ 提交于 2019-12-25 01:24:30
问题 I want to change the JLabel text for a short moment (there's a counter and if someone types in the wrong answer in a text field, I want to show a "wrong answer" instead of the counter. After a few seconds I want to show the counter again.) 回答1: For the fixed-delay execution of some code you want to use a timer object , in this case javax.swing.Timer. Here is a demo that applies to your situation: public static void main(String[] args) { SwingUtilities.invokeLater(()->{ JFrame frame = new

JLabel with HTML containing “<” and “>” characters

不打扰是莪最后的温柔 提交于 2019-12-24 21:29:05
问题 From time to time I use HTML in JLabels in Java Swing. Lastly I've came across something a little bit, for me, confusing... My code: public static void main(String[] args) { JFrame frame = new JFrame(); BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.PAGE_AXIS); frame.getContentPane().setLayout(layout); JLabel lbl1 = new JLabel("<html>Label 1: 300 > 100 and 90 < 200 </html>"); JLabel lbl2 = new JLabel("<html>Label 2: 300 > 100 and 90 < 200 </html>"); JLabel lbl3 = new

Difficulty in resizing an image which is stored in a JLabel

非 Y 不嫁゛ 提交于 2019-12-24 20:37:48
问题 I managed to increase an image of JLabel(which has an imageIcon stored in). When I press the increase size button, the original size of the image is increased on the panel, which is exactly what I want. However, when I click on my decrease size button(I figured dividing it by the scale might fix it)the label decreases, but the actual image appearance(size I guess)is changed. It's not decreasing the size, the same way my increase button increases the size. I have spent hours trying to figure

JLabel positioning is not working

强颜欢笑 提交于 2019-12-24 19:43:08
问题 I need to position the JLabel in my JFrame . I created a label and wanted to set its position, but both setAlignment and setBounds do not work. The label stays all the time at the top of the panel and it does not move. import java.awt.GridLayout; import javax.swing.*; public class Start extends JFrame { //JLabel label1 = new JLabel("HELLO!"); //JLabel label2 = new JLabel("CHOOSE LANGUAGE:"); public Start() { super(); setSize(480, 360); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(null);

Capturing and displaying an image using Java

邮差的信 提交于 2019-12-24 16:39:56
问题 I want to create an app which captures the screen (1280x720 res) and then displays it. The code for this is in a while loop so it's ongoing. Here's what I have: import javax.swing.*; import java.awt.Rectangle; import java.awt.Robot; import java.awt.image.BufferedImage; public class SV1 { public static void main(String[] args) throws Exception { JFrame theGUI = new JFrame(); theGUI.setTitle("TestApp"); theGUI.setSize(1280, 720); theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); theGUI

How to add text to JLabel

假如想象 提交于 2019-12-24 11:21:54
问题 I am creating a book reader, which takes the content of a file and sends it to an Object[]. I want this to be displayed, line by line on my page. I'm considering a loop of some sort that will add text to the label, but here's my question: How to I add text to the end of a JLabel, rather than setting the whole thing? 回答1: You can use getText() to retrieve what's there, and then setText() to set the new value. So to add something to the end, you'd do label.setText(label.getText()+"something");

JAVA: Swing JButton componnent (NullPointerException)

若如初见. 提交于 2019-12-24 08:50:11
问题 I am trying to show text - "You pressed Button" when you pressed one of buttons. I am getting an NullPointerException . I have initialized the buttons inside the constructor of the class and after initialization, I called the following method from main() . Here is the code: import java.awt.event.*; import javax.swing.*; import java.awt.*; public class ButtonDemo implements ActionListener{ JLabel jlab; ButtonDemo(){ JFrame jfrm = new JFrame("A Button Example"); jfrm.setLayout(new FlowLayout())

How do I set the color of a JLabel using Java?

会有一股神秘感。 提交于 2019-12-24 07:46:27
问题 I will be creating multiple Jlabel components upon a JButton click. I know how to create a label and set text inside but I want this label to have a color. I only know how to change the color of a label if it has a name but an important part of my program is when I declare the labels, I don't have names for them as shown in the code below: newPanel.add(new JLabel("jlabel text"), g); How can I set the color of the label? 回答1: yourLabel.setForeground(new java.awt.Color(r,g,b); 回答2: I don't have

increase height of a jlabel in positive y direction?

血红的双手。 提交于 2019-12-24 06:01:14
问题 When i setSize of a jLabel, normally it grows towards bottom. How can i increase the height in positive y direction ? After pressing init Current Result Expected result My source code private void initActionPerformed(java.awt.event.ActionEvent evt) { int p = Integer.parseInt(abc[0].getText()); int q = Integer.parseInt(abc[1].getText()); int r = Integer.parseInt(abc[2].getText()); int s = Integer.parseInt(abc[3].getText()); int t = Integer.parseInt(abc[4].getText()); one.setSize(20, p*10 );

increase height of a jlabel in positive y direction?

最后都变了- 提交于 2019-12-24 06:01:09
问题 When i setSize of a jLabel, normally it grows towards bottom. How can i increase the height in positive y direction ? After pressing init Current Result Expected result My source code private void initActionPerformed(java.awt.event.ActionEvent evt) { int p = Integer.parseInt(abc[0].getText()); int q = Integer.parseInt(abc[1].getText()); int r = Integer.parseInt(abc[2].getText()); int s = Integer.parseInt(abc[3].getText()); int t = Integer.parseInt(abc[4].getText()); one.setSize(20, p*10 );