jlabel

transparent parts of GIF/PNG image shown in black inside a JLabel java

两盒软妹~` 提交于 2019-12-19 10:30:52
问题 I have an image (gif or png) with some transparents parts which appear in black when put inside a JLabel. ClassLoader cl = this.getClass().getClassLoader(); ImageIcon img = new ImageIcon(cl.getResource("resources/myPicture.png")); label = new JLabel(img); How do I work around this problem ? I do not need the JLabel, maybe there is a better way to display the image correctly (i.e. with the transparency) directly on a JPanel ? Thanks David 回答1: Found the culprit ! Actually the picture is

Changing default JLabel font

孤人 提交于 2019-12-19 03:13:31
问题 How would I go about setting the default font for all JLabel instances. Instead of setting the font for each JLabel independently. 回答1: Use UIManager to define JLabel's default font: import java.awt.FlowLayout; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.UIManager; public class LabelFont { public static void main(String[] args) { Font oldLabelFont = UIManager.getFont("Label.font"); UIManager.put("Label.font", oldLabelFont.deriveFont(Font

How to word wrap text in JLabel?

浪尽此生 提交于 2019-12-19 03:13:08
问题 How can text like "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" which exceeds the width of the JLabel be wrapped? I have tried enclosing the text into html tags but no luck. Please give your suggestions. 回答1: A common approach is to not use a JLabel and instead use a JTextArea with word-wrap and line-wrap turned on. You could then decorate the JTextArea to make it look like a JLabel (border, background color, etc.). [Edited to include line-wrap for completeness per DSquare's comment] Another

Changing default JLabel font

人盡茶涼 提交于 2019-12-19 03:13:00
问题 How would I go about setting the default font for all JLabel instances. Instead of setting the font for each JLabel independently. 回答1: Use UIManager to define JLabel's default font: import java.awt.FlowLayout; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.UIManager; public class LabelFont { public static void main(String[] args) { Font oldLabelFont = UIManager.getFont("Label.font"); UIManager.put("Label.font", oldLabelFont.deriveFont(Font

EDT is not working properly with recursive method while updating lable

家住魔仙堡 提交于 2019-12-18 09:51:30
问题 //search files and directories public void getFile1(String directoryName) throws Exception { File directory = new File(directoryName); String str = directory.getName(); File[] fList = directory.listFiles(); if (fList != null) { for (File file : fList) { { if (file.isFile()) { st = (file.toString()); System.out.println(st); jLable1.setText(st);//jLable1 is not updating. String fileName = file.getName(); String strvirusCount=Integer.toString(virusCount); } else if (file.isDirectory()) {

Java Swing: unable to load image using getResource

允我心安 提交于 2019-12-18 09:31:49
问题 I'm trying to isolate where the problem could be when trying to add an image to the class directory. (Doing this so when I export as a runnable JAR, the image is included in the package). So I've got the strawberry.jpg file sitting in 'C:\Users\sean\workspace\myApps\src\testing' Could you advise what I'm missing? Thanks! package testing; import java.awt.*; import javax.swing.*; public class IconTest { public static void main(String[] arguments) { JFrame frame1 = new JFrame(); frame1.setTitle(

Java Swing: unable to load image using getResource

六眼飞鱼酱① 提交于 2019-12-18 09:30:06
问题 I'm trying to isolate where the problem could be when trying to add an image to the class directory. (Doing this so when I export as a runnable JAR, the image is included in the package). So I've got the strawberry.jpg file sitting in 'C:\Users\sean\workspace\myApps\src\testing' Could you advise what I'm missing? Thanks! package testing; import java.awt.*; import javax.swing.*; public class IconTest { public static void main(String[] arguments) { JFrame frame1 = new JFrame(); frame1.setTitle(

JAVA Swing - Setting JLabel equal to a String in another class

假装没事ソ 提交于 2019-12-18 09:27:51
问题 I have a method called getTheUserInput in a class which returns a String which updates based on user actions, which is located inside a class called Board.java. I have action which adds data to a String which I know works. In my other class I have a JLabel which has been set to equal the returned String of the method, as follows: JLabel l = new JLabel(b.getTheUserInput()); However, when I run the application no matter what input the user provides, the string updates, but the JLabel stays

JLabel setText not updating text

大憨熊 提交于 2019-12-18 09:12:39
问题 I am trying to update a JLabel by using the setText() method, but I can't redraw JLabel. Do I have to use the repaint() method to do that? Here is the part of code, I do not get any errors, but it is not updating the JLabel. public void actionPerformed(ActionEvent e) { fc = new JFileChooser(); if(e.getSource() == addButton) { int returnVal = fc.showOpenDialog(Main.this); if (returnVal == JFileChooser.APPROVE_OPTION) { filesList = fc.getSelectedFiles(); setFilesList(filesList); StringBuilder

More than one JPanel in a Frame / having a brackground Image and another Layer with Components on the top

試著忘記壹切 提交于 2019-12-18 09:05:27
问题 I've got a JFrame with a JPanel in which there is a JLabel with an ImageIcon(). Everything's working perfectly, problem is i now want to add another JPanel with all the other stuff like buttons and so on to the JFrame. But it still shows the background Image on top and nothing with the second JPanel. Can someone help me? Here is an extract of my code: JFrame window = new JFrame("Http Download"); /* * Background Section */ JPanel panel1 = new JPanel(); JLabel lbl1 = new JLabel(); /* *