jlabel

Moving JLabel to other JLabels - GUI

北城余情 提交于 2019-11-27 02:18:48
I'm trying to make a JLabel move across other JLabels, only 1 timer works right now. It is supposed to operate like a train moving across a track, going all the way around the track and ending up right back where it started from. I'm not sure how to make it go all the way around, any help is appreciated. Thank you. import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; import javax.swing

make a JLabel wrap it's text by setting a max width

ⅰ亾dé卋堺 提交于 2019-11-27 01:54:50
I have a JLabel which has a lot of text on it. Is there a way to make the JLabel have a max width so that it will wrap the text to make it not exceed this width? Thanks camickr No. You can use HTML in the label, but then you must hard code the break tag. A better approach is to use a JTextArea and turn wrapping on. You can change the background,foreground, font etc. of the text are to make it look like a label. Note, this answer is outdated as of at least Java 7. As per @darren's answer, you simply need to wrap the string with <html> and </html> tags: myLabel.setText("<html>"+ myString +"<

Make JLabel background transparent again

蹲街弑〆低调 提交于 2019-11-26 23:29:27
问题 I have a JLabel that changes its background color when the mouse enters it. The problem I have is that I want the JLabel to become transparent after the mouse exits. Is there a statement I can use to accomplish this? 回答1: It's a lazy holiday here in Germany, so combining the two answers: final JLabel label = new JLabel("some label with a nice text"); label.setBackground(Color.YELLOW); MouseAdapter adapter = new MouseAdapter() { /** * @inherited <p> */ @Override public void mouseEntered

Updating an image contained in a JLabel - problems

 ̄綄美尐妖づ 提交于 2019-11-26 23:18:32
The part of the application that I am currently having trouble getting to work is being able to scroll through and display a list of images, one at a time. I'm getting a directory from the user, spooling through all of the files in that directory, and then loading an array of just the jpegs and pngs. Next, I want to update a JLabel with the first image, and provide previous and next buttons to scroll through and display each image in turn. When I try to display the second image, it doesn't get updated... Here's what I've got so far: public class CreateGallery { private JLabel swingImage; The

Adding a timer and displaying label text

你。 提交于 2019-11-26 22:02:11
问题 I have a JLabel. Initially i have set some text to it. JLabel j = new JLabel(); // set width height and position j.setText("Hello"); I only want the text Hello to display for 5 seconds. then i want the text Bye to be displayed. How could i do this. My workings; but i know it's wrong as it only executes 1 if-else block at a time. I think i will need a timer or a counter. to get this working. Help ? long time = System.currentTimeMillis(); if ( time < (time+5000)) { // adding 5 sec to the time j

JLabel displaying countdown, java

泪湿孤枕 提交于 2019-11-26 21:56:49
问题 I've got a "status" JLabel in one class (named Welcome) and the timer in another one (named Timer). Right now, the first one displays the word "status" and the second one should be doing the countdown. The way I would like it to be, but don't know how to - display 10, 9, 8, 7 ... 0 (and go to the next window then). My attempts so far: // class Welcome setLayout(new BorderLayout()); JPanel area = new JPanel(); JLabel status = new JLabel("status"); area.setBackground(Color.darkGray); Font font2

Java JLabel/JButton: on some systems I get “…” (an ellipsis) and on some systems I don't. how can I force to disable the ellipsis at all?

一笑奈何 提交于 2019-11-26 21:55:17
问题 On most systems, the content in my JLabel just shows fine. It is also resided in a way that it should be always big enough to show its content text because I basically do this: label.setText(text); label.setFont(new Font(fontName, 0, 12)); int width = label.getFontMetrics(label.getFont()).stringWidth(text); int height = 21; // this should always be enough label.setBounds(new Rectangle(x, y, width, height)); But on some systems (not my own so I cannot really debug it that easy), it cuts the

Drag and Drop custom object from JList into JLabel

隐身守侯 提交于 2019-11-26 19:06:59
I have a JList containing an ArrayList of custom objects and I'm trying to create a drag and drop into fields. I'm having trouble understanding how to package and receive the object in Transferable. This is about as far as I've gotten: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.util.*; public class FlightProjectInterface extends JFrame{ //create GUI Objects private JFrame primaryFrame; private JPanel createFlightPanel; private JPanel aircraftLayout; private JList personsJList, personsOnFlightJList; private JTextField pilotLabel,

Place JLabel on top of JLabel with image in

人走茶凉 提交于 2019-11-26 18:33:53
问题 I am pretty sure that this question has been asked before, but my case is slightly different as in i am trying to place a JLabel on top of a JLabel acting as a background, I want to display changing numbers using the JLabels and the numbers need to display over the background, however i am a bit of a swing n00b, thanks in advance, Jonathan 回答1: Without fully appreciating your requirements, if you simply need to display text over a background image, you'd be better off placing the label on top

How do I create an event handler for a JLabel?

心不动则不痛 提交于 2019-11-26 18:33:06
问题 I want to make it so that if I click on the JLabel, the label becomes a new label with another image attached to it. So far my code looks like: public class Picture extends JFrame { private ImageIcon _image1; private ImageIcon _image2; private JLabel _mainLabel; private JLabel _mainLabel2; public Picture(){ _image1 = new ImageIcon("src/classes/picture1.jpg"); _image2 = new ImageIcon("src/classes/picture2.jpg"); _mainLabel = new JLabel(_image1); _mainLabel2 = new JLabel(_image2); add(