jlabel

Getting jLabel image url in Java

假装没事ソ 提交于 2019-12-12 01:57:29
问题 I'll make it short. I've put a jLbl_show and in a if condition I've set an image for it. if(int c==1){ jLbl_show0.setIcon(new ImageIcon(getClass().getResource("/img/wrong.png"))); } else{ jLbl_show0.setIcon(new ImageIcon(getClass().getResource("/img/ok.png"))); } But, as now the image is set i need to take the image URL to another condition . which is like; if(imageURL is "/img/ok.png"){ do somthing } elseif (imgURL is "/img/wrong.png"){ do something } is there a way to do this? 回答1: do

Type mismatch error when adding JLabel/JPanel to Scala Swing Panel

落花浮王杯 提交于 2019-12-12 01:50:06
问题 I'm trying to incorporate a java native JLabel (or a JPanel) to a scala swing application and I'm stuck with the compile error. The code I'm trying to run is the following. package com.david import javax.swing.JPanel import scala.swing._ object Hello extends SimpleSwingApplication { def top = new MainFrame { title = "First Swing App" contents = new JPanel() } } The compiler gives me the following error. $ sbt compile [info] Set current project to MyGui (in build file:/home/david/programming

Dynamic graphic programming (Animation)

孤街浪徒 提交于 2019-12-12 01:15:03
问题 I am trying to code a simple animation like a moving circle. I have tried using getGraphics() and work with that but it's not dynamic and it's painted for just one time So please help me and guide me to code a dynamic graphic program. I mean for example defining a function and every time when it called, it draws a line on a label. 回答1: Here is how to make a growing rectangle: public class MovingRectangle extends JPanel { private Timer timer = new Timer(500, new ActionListener() { public void

Updating jlabel temperature on the gui in java when temperature is updated

北战南征 提交于 2019-12-12 00:56:13
问题 Hi I am trying to create a gui that will update the temperature every time the temperature sensor sends back a signal and update the jlabel value. Right now I am able to update the gui label by pressing the update button, however i want it to update automatically without pressing the "update button". I have tried a lot of method including repaint() , and revalidate() , and using different type of swing timers but still cannot get it to work. Can someone please help me out here? Thanks I will

Change JLabel Background on MouseRelease Event

混江龙づ霸主 提交于 2019-12-12 00:45:30
问题 I am trying to write a Java program that when you click on a certain element in the JFrame, the background of a JLabel is changed. The function that the event handling method calls to change the background does not work when called from the event, however it does work whenever you call the method somewhere independent of any event. Does anyone know how you would go about changing the background on MouseRelease event, since using an event handling method like so doesn't work? private void

Removing MouseListener() from a JLabel

烈酒焚心 提交于 2019-12-11 23:36:43
问题 I added a MouseListener to a JLabel . Now if I want to disable this MouseListener associated with the JLabel , when the label is clicked once, how can I do it. I know there is a big way to set a boolean or int variable when the label is clicked and then call a method and remove MouseListener there, but I want to learn a compact and easy way. Is there a way to do this? 回答1: In your mouse listener: public void mouseClicked(MouseEvent event) { // Do stuff... ((Component) event.getSource())

Icon in Src folder

て烟熏妆下的殇ゞ 提交于 2019-12-11 23:31:57
问题 I am trying to create an icon for a jLabel using an image in my src folder. I am not sure of the file path I would use when creating this icon. if (CoverImg.equals("")) { Icon noImage = new ImageIcon("/animedb/NoImage.jpg"); CoverImageLabel.setIcon(noImage); CoverImageLabel.setHorizontalAlignment(SwingConstants.CENTER); } else { Icon icon = new ImageIcon(CoverImg); height = icon.getIconHeight(); width = icon.getIconWidth(); CoverImageLabel.setIcon(icon); CoverImageLabel.setHorizontalAlignment

Image reading error

自作多情 提交于 2019-12-11 20:17:25
问题 I am trying to make an image writer that will read a template image and then write text on it, then create a new image with the new text. For some reason I am getting errors when my code seems fine to me. Here is the code below: public class GUI extends JFrame{ private JPanel p1 = new JPanel();//Puts tiles in, and organizes them for you private JPanel p2 = new JPanel();//Holds trash tiles JLabel ll = new JLabel(); //private JPanel p3 = new JPanel();//Holds trash tiles public GUI(){ this

JFrame adding Text not working. Two GUI appear

≡放荡痞女 提交于 2019-12-11 20:14:48
问题 I am trying to create a simple JFrame menu where there is a nice background, which works, along with some text. The text is a bit buggy. Here is how it looks (http://imgur.com/nRpzA30) As you can see, only one line of the text appears not the second line. Along with that. Two GUI's appear when I run the program. One is completley empty, and one looks like the picture above. Finally I can't use the method logo.setHorizontalAlignment(JLabel.NORTH); without getting an error, same with a few

JLabel on JPanel doesn't update when setText from another method

只愿长相守 提交于 2019-12-11 19:36:14
问题 Thank you for your help. I'm a newbie trying something quite simple. I want to have a window (panel) with a text (JLabel) that changes every few seconds. The whole application is working perfectly except for the JLabel that is being updated (the text does change), but it doesn't show on the window (panel). The window keeps the same text from beginning to end even though I have checkpoints that tell me that the text of the JLabel is being updated and changing. I've looked for the same issue