jlabel

Java: how to add image to Jlabel?

断了今生、忘了曾经 提交于 2019-12-17 09:43:06
问题 Image image = GenerateImage.toImage(true); //this generates an image file JLabel thumb = new JLabel(); thumb.setIcon(image) 回答1: You have to supply to the JLabel an Icon implementation (i.e ImageIcon ). You can do it trough the setIcon method, as in your question, or through the JLabel constructor: Image image=GenerateImage.toImage(true); //this generates an image file ImageIcon icon = new ImageIcon(image); JLabel thumb = new JLabel(); thumb.setIcon(icon); I recommend you to read the Javadoc

Moving JLabel to other JLabels - GUI

蹲街弑〆低调 提交于 2019-12-17 06:56:20
问题 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

Drag and Drop custom object from JList into JLabel

人走茶凉 提交于 2019-12-17 04:35:25
问题 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

ImageIcon by JLabel example with absolute positioning

寵の児 提交于 2019-12-14 00:06:09
问题 I have seen a lot of example code but none that specifically shows me how to display an ImageIcon through the use of a JLabel on a JFrame without using a layout manager. I am repeatedly told that absolute positioning is a hassle and less efficient than a layout manager but I'd prefer complete control over where my elements are going. A full scale example class (with no extra things added) of a JLabel that will display an image on a JFrame with absolute positioning would be much appreciated ,

How do I update a JLabel everytime a JComboBox changes?

北城余情 提交于 2019-12-13 20:05:41
问题 I have a JComboBox with 12 different selections, and depending on what is selected I want the question (JLabel) to change matching the selection. I've tried an if statement to see what is selected and if it matches what should be selected, then the question changes accordingly, but the JLabel never really changes under an circumstance. Code import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import javax

Resizing JLabel ImageIcon with HTML

十年热恋 提交于 2019-12-13 18:40:27
问题 So I looked through this thread and saw the suggestion of using HTML for resizing. I've been going through the Oracle website but it only provided example for text customization in JLabels using HTML. Can I get an example of a JLabel with HTML parameters? 回答1: This basically requires you to have a URL reference to the image in question. This is quite easy to achieve if the image is an embedded resource (as demonstrated below), but you should be able to generate a URL from file using File

How to align multiple textfields on a background image within a JOptionPane?

旧街凉风 提交于 2019-12-13 18:31:55
问题 I want to have multiple textfiled to be aligned in a customized order, so that they are on the top of the background image. I tried to use setBounds but it did not work: import javax.swing.*; public class TestJP { public static void main(String[] args) { JLabel myLabel = new JLabel(); myLabel.setIcon ( new ImageIcon("system\\myBackground.jpg")); myLabel.setBounds(0,0,750,500); JTextField login = new JTextField(5); login.setBounds(50,50,20,100); // This does not work JPasswordField password =

How to change font size of all private JLabels

隐身守侯 提交于 2019-12-13 14:40:58
问题 I have seen similar questions such as this, but in my case I have 25+ private JLabels that I give a value for when I declare it. I use a GridBagLayout in my constructor to add these JLabels to a JPanel. If I use something along the lines of the answer given in the link, it will only change JLabels that were added in the constructor. So it seems to me that if I want to change the font size of my private JLabels, I would have to either define the font size for them individually, or change the

Add image to JPanel within JLabel

老子叫甜甜 提交于 2019-12-13 11:28:56
问题 I have this code: import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Interface { private JPanel panel; private JPanel buttonPane; private JLabel label; private JLabel label2; private JTextField textfield; private JTextField textfield2; private JTextField textfield3; private JTextField textfield4; private JTextField textfield5; private JButton button; private JButton button2; private JButton button3; private

Thread and JLabel in Swing- Not working properly

て烟熏妆下的殇ゞ 提交于 2019-12-13 10:30:09
问题 Please look at the code below. import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JFrame; import javax.swing.JPanel; class thread_jishu extends Thread{ @Override public void run(){ int p=-1; for(;;){ //here continuously checking that whether //the value of label_thread.i is equals to p or not if(label_thread.i!=p){ try{ Thread.sleep(1000); }catch(Exception e){} label_thread.lb.setText("after sleeping at -> "+label_thread.i); // here i want to set the JLabel // text