jlabel

Calibri Font when in <html> text moves to the bottom part of the component

只谈情不闲聊 提交于 2021-02-11 14:00:28
问题 There is not a lot to explain. Just see the MCVE/image below: public class FontExample extends JFrame { private static final Font FONT = new Font("Calibri", Font.PLAIN, 14); public FontExample() { super(""); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout()); JLabel withoutHtml = new JLabel("hello stackoverflow"); withoutHtml.setFont(FONT); withoutHtml.setBorder(BorderFactory.createLineBorder(Color.red)); add(withoutHtml); JLabel withHtml = new JLabel("<html><body

can JLabel have img tags

[亡魂溺海] 提交于 2021-02-07 13:25:42
问题 I am trying to display a JLabel which has a few lines of text and an image as follows: String html = "<html> hello </br> <img src = \"/absolute/path/here\" height = \"30\" width =\"40\"/> </html>"; JLabel l = new JLabel(html); For the image all I get is a broken image, is it possible to nest img tags inside a JLabel? EDIT: I want to add multiple images to the JLabel so I don't think the use of an ImageIcon will do here. Thanks 回答1: Rather then try to have multiple images on a single JLabel

Set Label in Java to Image-Format Issue

孤人 提交于 2021-02-05 08:08:00
问题 I am trying to set the label in a java program to an image. It seems, however, that it does not work for .bmp images I am looking for a converter which will allow me to convert an image from a .bmp to a .jpg with the same file name. This converter needs to be controlled by the java program, which has the name and location of the image that needs to be converted. Any help would be greatly appreciated as I have spent hours on this :P Thanks *Edit: The program needs to be able to be packaged

Set Label in Java to Image-Format Issue

走远了吗. 提交于 2021-02-05 08:07:43
问题 I am trying to set the label in a java program to an image. It seems, however, that it does not work for .bmp images I am looking for a converter which will allow me to convert an image from a .bmp to a .jpg with the same file name. This converter needs to be controlled by the java program, which has the name and location of the image that needs to be converted. Any help would be greatly appreciated as I have spent hours on this :P Thanks *Edit: The program needs to be able to be packaged

JLabel - is it possible to set RenderingHints.VALUE_TEXT_ANTIALIAS_OFF?

谁都会走 提交于 2021-01-28 05:16:17
问题 Is it possible to turn off ANTIALIAS in JLabel ? Something like this (but it is not working..): @Override public void paintComponent(Graphics g) { Graphics2D graphics2d = (Graphics2D) g; graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); super.paintComponent(g); } } Or should I create custom Label where I can easily set this ANTIALIAS value? The goal is to make the text not fuzzy. 回答1: Found the solution (first lines when application

Java: How to continuously update JLabel which uses atomicInteger to countdown after ActionListener

拟墨画扇 提交于 2021-01-28 04:00:47
问题 I was reading different threads on the subject which suggested the Swing Timer class or SwingUtilities.InvokeLater ...but I am having a lot of trouble wrapping my head around them. I used atomicInteger to create my countdown timer and it works fine in the console. However, When I try to incorporate it in Swing, it only updates the starting and ending value (e.g. set a 5 sec countdown will display in the frame: "5" -> after 5 seconds -> "0". Is there any simple way for me to keep and "refresh"

How to convert JLabel.getIcon() to BufferedImage

大兔子大兔子 提交于 2021-01-28 01:35:03
问题 I have a JLabel that contains only an icon, and I can get the Icon with label1.getIcon(), but I can't figure out how to convert that Icon into a BufferedImage. Just FYI, I'm not talking about ImageIcon, only Icon. Also, I have seen the question at How to convert Icon from JLabel into BufferedImage?, but I can't seem to figure it out. As always, any examples or explanation are much appreciated. Thanks! 回答1: You may try this. // Get the icon Icon ico = label1.getIcon(); // Create a buffered

Java changing the text of JLabel inside another method

时光怂恿深爱的人放手 提交于 2021-01-27 17:35:36
问题 I want to change the text of a JLabel outside of the method I created it in. I've looked through the other pages on the same topic but I still cannot get it to work. Perhaps I am lacking knowledge of Java to solve this by myself. Would you please help me? package autumn; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JLabel; public class Main { private JFrame frame; JLabel TestLabel; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() {

Change font of JLabel

我怕爱的太早我们不能终老 提交于 2021-01-27 04:18:52
问题 how to change Font of JLabel ? I try this but with no succes: JLabel nadpis = new JLabel(); nadpis.setFont(new Font("Papyrus", Font.ITALIC, 100)); nadpis.setText("hi"); Just size is changed but Font is still same 回答1: I didn't see papyrus in my available fonts. How can I add it? Look in the Font methods for the createFont() variants. 来源: https://stackoverflow.com/questions/7859551/change-font-of-jlabel

Java swing JButton/JLabel: icons are not displayed in their original size

帅比萌擦擦* 提交于 2021-01-11 02:54:12
问题 I have png icons and use them as icons in JButton / JLabel . The problem is that the image displayed at runtime is larger than the original icon, and because of this resizing, it's super ugly. Here is an example: Original icon (left) and how it's rendered in the JButton (right) The source code for this minimal example is simply: public class Main { public static void main(String... args) { JFrame frame = new JFrame("Test"); frame.setBounds(0, 0, 120, 80); frame.setDefaultCloseOperation(JFrame