jlabel

Creating a Grid in Java

为君一笑 提交于 2019-12-10 15:07:23
问题 As a way of learning Java, I'm writing this little application for grade schoolers to practice basic math. The idea is that the kid does any number of math problems, as long as they are in the app, it just continues to throw problems at them until they click a 'Done' button. When they decide to be done, I want a new JFrame to come up that will show them all of the problems they attempted, along with their answer, and whether they got the problem right or wrong. The advice that I am looking

Why does JLabel not display '/' when it is the first character?

﹥>﹥吖頭↗ 提交于 2019-12-10 13:54:09
问题 I have an swing panel with a JLabel inside of it. The JLabel looks like this: new JLabel("<html>/Foo <br/>/Bar <br/>/Foo<br/>/Bar</html>"); However it displays in the UI like the following: Bar Foo Bar For some reason, the first line just disappears. If I take out the slash or remove the html tags, it works as expected. Is there a way to make the first line show up with the slash? The reason this even showed up is that we have JLabels which are populated by third party data. I could

JLabel text is garbled

送分小仙女□ 提交于 2019-12-10 10:39:25
问题 I'm seeing a strange issue involving a JLabel that is used to display a range of numbers. The text of the label is typically something like 0.0 - 100.0 (for example). The problem is that for a select few users, the text appears garbled. In this example, the text would show up as /-/,0//-/ . Here's what I know so far: It appears to be some sort of off-by-one bug since each character displayed is one Unicode character behind the expected character. The dash character between the two numbers is

How to rotate Swing text?

邮差的信 提交于 2019-12-10 04:08:01
问题 Is there a way to rotate Swing text such as in a JLabel between 0 and 360 (or between -180 and 180) degrees in 1 degree steps? 回答1: Yes. Look at Graphics2D.rotate(). For a JLabel, I think you could override the paintComponent() method to call rotate(x), then call the existing paintComponent(), then call rotate(-x). e.g. protected void paintComponent(Graphics g) { Graphics2D g2 = ( Graphics2D )g; g2.rotate(theta); super.paintComponent(g2); g2.rotate(-theta); } I haven't tried this. You might

How to get a multilined JLabel (or a JTextArea looking totally the same) without HTML

99封情书 提交于 2019-12-09 03:18:30
问题 I cant believe fastest solution for a multilined JLabel is the following one (text comes from a var, and so I dont want to put HTML code manually every x chars, its so ugly): public class JMultilineLabel extends JTextArea{ private static final long serialVersionUID = 1L; public JMultilineLabel(String text){ super(text); setEditable(false); setCursor(null); setOpaque(false); setFocusable(false); setFont(UIManager.getFont("Label.font")); setWrapStyleWord(true); setLineWrap(true); } } ... sure

Creating a Count Up timer to Break in java

浪子不回头ぞ 提交于 2019-12-09 00:55:05
问题 I'm trying to implement a timer based scoring system for a puzzle application i am writing. Can someone provide me with an example case of creating a JLabel or Panel in swing, containing a visibly counting timer (in seconds from 0), which stops, on a call from a method. And returns its value. Example: hrs:mins:seconds [00:00:00] [00:00:01] .. etc.. overwriting the previous entry. Thanks EDIT: this is an adaptation of the example code linked by trashgod: ClockExample, which uses simple if

Refreshing a JLabel icon image

偶尔善良 提交于 2019-12-09 00:39:26
问题 I'm displaying an image in a JFrame using a JLabel and setting it's icon. It works the first time, but whenever I go to change the image, it remains what I set it the first time, so I've tried this and still the same result. contentPane.remove(lblPlaceholder); lblPlaceholder = null; lblPlaceholder = new JLabel(""); lblPlaceholder.setBounds(10, 322, 125, 32); contentPane.add(lblPlaceholder); lblPlaceholder.setIcon(new ImageIcon("tempimage.png")); How can I get it to change it's image? I've

JLabel doesn't appear before sleep

ぐ巨炮叔叔 提交于 2019-12-08 12:22:39
问题 I am working on a simple Swing program that places one label on the frame, sleeps for one second, and then places another label on the frame as follows: import javax.swing.*; import java.util.concurrent.*; public class SubmitLabelManipulationTask { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Hello Swing"); final JLabel label = new JLabel("A Label"); frame.add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 100); frame

Removing a JLabel after 10 seconds

不打扰是莪最后的温柔 提交于 2019-12-08 08:47:12
问题 If I have a JLabel, how do I remove it after 10 seconds? I want to be able to view the JLabel after I've removed it. I figure it might have something to do with javax.swing.Timer and JLabel.setVisible(false) . 回答1: Try this: final JLabel label = new JLabel("myLabel"); int delay = 10000; //milliseconds ActionListener taskPerformer = new ActionListener() { public void actionPerformed(ActionEvent evt) { label.setVisible(false) } }; new javax.swing.Timer(delay, taskPerformer).start(); 来源: https:/

Adding text to a label from another class - Simple Logic Issue

我的未来我决定 提交于 2019-12-08 07:37:20
问题 I have a label and a button in a class called FrameTest , when i press the button, a method named buttonpressed get's executed from the class Test . In this buttonpressed method i will set a text to the label found in the FrameTest class. The problem i have is that, the text for the label is not getting set. The reason is that i am creating a separate object to call the buttonpressed method; public void actionPerformed(ActionEvent arg0) { Test t = new Test(); t.buttonpress(); } and i am