jlabel

Dynamically change the width of JDialog

孤人 提交于 2019-12-06 10:59:47
I have created a JDialog which contains a JLabel. Because the length of text, which changes based on users' input, can contain a large number of characters, there is the need to dynamically change the length of the JDialog based on the size of length of the JDialog. I have tried the pack() method but it's not the case for it. Can anyone give me some tips? Thanks in advance! mKorbel getPreferredSize for JLabel - basically you have to get textLength from JLabel in pixels, there are 3 correct ways, but I love: SwingUtilities.computeStringWidth(FontMetrics fm, String str) Now you are able to

Java JLabel ignores alpha value of foreground color when rendering HTML

怎甘沉沦 提交于 2019-12-06 10:53:29
问题 When I use a JLabel with a foreground color which has an alpha value, like so: JLabel label = new JLabel( "This is non HTML text with correct alpha color" ); label.setForeground( new Color( 1.0f, 1.0f, 1.0f, 0.5f) ); the label is displayed correctly with 0.5-alpha, so 50% gray. But when I change the text to HTML (to have more control over the text rendering), like so: JLabel label = new JLabel( "<html><p>This is HTML text with incorrect alpha color</p></html>" ); label.setForeground( new

How to add superscript to Label text in Javafx 8

时间秒杀一切 提交于 2019-12-06 07:43:25
问题 I am writing my first JavaFX application and I cannot find how to make some of the text in a Label to be superscript. In Swing it was easy enough to use HTML tags, but this option is not available in JavaFX. I have searched through many of the api's including Label, Font, TextFlow, Oracle docs and samples, and the internet in general. Thank you. 回答1: The WebView is more flexible, but, depending upon which font you are using and the content of the superscript, there are Unicode superscript

How do you stop a JLabel changing its size when its text changes?

笑着哭i 提交于 2019-12-06 04:48:30
问题 I'm generating some JComponents in code and using the GridBag layout to arrange them. My layout consists of 12 rows and 3 columns, with each row consisting of a JSlider, a JCheckBox and a JLabel. Here's the code I'm using to generate the UI: final int NUM_MOTORS = 12; // This is the panel I'm adding the components to. pnlMotorSliders.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); for (int i = 0; i < NUM_MOTORS; ++i) { c.gridy = i; // Create the slider JSlider

image loading using a JFileChooser into a JFrame

孤者浪人 提交于 2019-12-06 01:58:38
I am trying to write a code that displays an image selected using a JFileChooser into another JFrame .I tried the following code below but only got the following errors. Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:228) at power.<init>(fCGUI.java:53) at fCGUI.main(fCGUI.java:11) Here is the code: import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; public class fCGUI { public static void main(String []args)

Table cells with HTML strings inconsistently rendered as multiline

久未见 提交于 2019-12-06 01:38:42
问题 Cells of one of columns in my table are HTML strings. HTML is used to provide some color indication. Usually the width of the column is enough to contain the whole string. But when it is not enough then the string is nicely cut on a word boundary. This is the desired behavior. The default cell renderer is used. I noticed that occasionally, some interaction with the table triggers the rendererer to wrap the string. As I understand, wrapping the HTML string is a normal behavior of JLabel from

JLabel shifts the text vertically down while displaying HTML

半腔热情 提交于 2019-12-05 20:25:14
I would like to understand why a JLabel, rendering HTML, shifts the vertical position of it's output text, whereas a JLabel which renders non-HTML, does not. Java version used : 1.6.0_37 Swing Look and Feel used : Windows ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel") OS : Windows 7 64 Bit I did not put a SSCCE together since the code is really trivial. But if it helps please say so. I rather give an examples using an images displaying the behavior: I put a JPanel as the container around the JLabel to visualize the label's bounds. After setting the font and text for the JLabel, the

How to resize Image/IconImage in JLabel?

女生的网名这么多〃 提交于 2019-12-05 19:23:34
Here's my code: String s = "/Applications/Asphalt6.app"; JFileChooser chooser = new JFileChooser(); File file = new File(s); Icon icon = chooser.getIcon(file); // show the icon JLabel ficon = new JLabel(s, icon, SwingConstants.LEFT); Now, the image extracted from the icon is really small. How can I resize it? import java.awt.*; import java.awt.image.*; import javax.swing.*; import java.io.*; class BigIcon { public static void main(String[] args) { JFileChooser chooser = new JFileChooser(); File f = new File("BigIcon.java"); Icon icon = chooser.getIcon(f); int scale = 4; BufferedImage bi = new

Enable blinking of JLabel 3 times and then remain invisible/disappear

拟墨画扇 提交于 2019-12-05 19:10:32
I intend on writing java code which controls a JLabel to blink three times and then after the third blink enable the text within it to remain transparent/"disappear." As indicated from the code below, I've been able to write a JLabel which continuously blinks but would like to create one that blinks only three times and then enable the text within it to remain transparent. public class BlinkLabel extends JLabel { private static final long serialVersionUID = 1L; private static final int BLINKING_RATE = 1000; // in ms private boolean blinkingOn = true; public Timer timer; public BlinkLabel

java how to make a JLabel with vertical text? [duplicate]

非 Y 不嫁゛ 提交于 2019-12-05 18:16:03
This question already has an answer here: How do I present text vertically in a JLabel ? (Java 1.6) 5 answers i need to make a vertical JLabel - a JLabel which shows it's text vertically- i searched google but i didn't find a good answer. how to do that? You could use the class VerticalLabelUI created by a dev: http://tech.chitgoks.com/2009/11/13/rotate-jlabel-vertically/ You can create a method that will transform your text into an HTML code like this: public static String transformStringToHtml(String strToTransform) { String ans = "<html>"; String br = "<br>"; String[] lettersArr =