jlabel

How to get a multilined JLabel (or a JTextArea looking totally the same) without HTML

牧云@^-^@ 提交于 2019-12-01 06:00:44
I cant believe fastest solution for a multilined JLabel is the following one (text comes from a var, and so I dont want to put HTML code manually every x chars, its so ugly): public class JMultilineLabel extends JTextArea{ private static final long serialVersionUID = 1L; public JMultilineLabel(String text){ super(text); setEditable(false); setCursor(null); setOpaque(false); setFocusable(false); setFont(UIManager.getFont("Label.font")); setWrapStyleWord(true); setLineWrap(true); } } ... sure it isnt a better way to handle this???? Boro If you want a multilne label then you simply use HTML in

Swing/Java: How to use the getText and setText string properly

旧街凉风 提交于 2019-12-01 04:32:09
I'm trying to make input nameField appear in a Label called label1 after a Button called button1 is clicked. Right now it says: 'txt' and I understand why. But I don't know how I can use the string! Can anyone explain me what I'm doing wrong and how to use this string properly? import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class thisismytest2 { public static void main(String[] args) { final

How to change gap in swing label

倖福魔咒の 提交于 2019-12-01 03:59:58
问题 I create some label: leftLabel.setAlignmentX(Component.CENTER_ALIGNMENT); leftLabel.setFont(new Font(FONT, Font.PLAIN, 280)); leftLabel.setBorder(BorderFactory.createTitledBorder("aaa")); leftLabel.setText("0"); which look like this: As you can see there are big gap up and down. How I can reduce it ? 回答1: You need to tweak the border insets, import java.awt.Component; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Insets; import javax.swing.JFrame; import javax.swing.JLabel

Java JLabel, break text to next line?

元气小坏坏 提交于 2019-12-01 03:37:30
It's been awhile since I asked a question! I'm developing an application in Java where JLabels are used. Anyway, as you may or may not be able to see from the picture below, the text that says Category Test gets cut off and ends up saying Categor... instead. Is there any way that I can "break" the text once it fills up the width of the label? Here is the image: What I did I used a JTextPane like so: JTextPane text = new JTextPane(); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setAlignment(attr, StyleConstants.ALIGN_CENTER); pane.add(text, c); Then I added my text, but

how to center JLabel in Jframe Swing?

我只是一个虾纸丫 提交于 2019-12-01 03:30:23
I have this working code for a stop watch in Swing. I want to have the label Time Remaining 300 seconds centered on the second line`. here is my code. import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; public class TimerGUI extends JPanel { JLabel promptLabel, timerLabel; final int count = 30; JButton start; JButton end; Timer timer; public TimerGUI() {

JLabel html text ignores setFont

怎甘沉沦 提交于 2019-12-01 03:20:58
I've just started porting my Swing app from OS X to Windows and things are painful with JLabel s. I've noticed that the font specified to setFont is ignored if the label's text is HTML (this doesn't happen on the Mac). The HTML formatting is EXTREMELY useful for readability on complicated displays. Under normal circumstances I'd specify the font in an HTML tag, but the font I'm using is loaded at runtime using Font.createFont with a ttf out of the JAR. I tried using the loaded font's name in the font tag, but that didn't work. Is there any way I can use a loaded awt.Font with an html-ified

Loading animated GIF in JLabel weirdness

大憨熊 提交于 2019-12-01 02:53:59
问题 I'm trying to load an animated GIF in a JLabel. While this works: URL urlsd; try { urlsd = new URL("http://pscode.org/media/starzoom-thumb.gif"); ImageIcon imageIcon = new ImageIcon(urlsd); JLabel progress = new JLabel(imageIcon); progress.setBounds(5, 20, 66, 66); contentPane.add(progress); } catch (MalformedURLException e) { e.printStackTrace(); } This, on the other hand, does not, and I don't want to get the GIF from an URL, since I already have the GIF. Result of loading this shows only

How to highlight part of a JLabel?

主宰稳场 提交于 2019-12-01 02:27:25
问题 Before any one suggests HTML, I explain later why thats not an option here. I have a table that contains a column with text cells in it. I need to be able to highlight some of the text in each cell. So for example if the cell contained "cat foo dog"... I might want to highlight foo. My current method is to use a custom TableCellRenderer that puts html into a JLabel component that gets rendered and for a time it was good. Then I noticed that when the text in the cell became too long to fit in

Java: How do I drag and drop a control to a new location instead of its data?

大兔子大兔子 提交于 2019-12-01 01:54:36
In Java, what is the best way to perform drag and drop when the item being dragged is the source control itself? I know a control is nothing but data too, but the difference does have UI impacts. I'm creating a solitaire-style game where I have card objects of class Card derived from JLabel. I want to drag that card to another location by dropping it onto a yet-to-be named Destination control. During the drag, I want the card to visually move with the mouse and when dropped I want it to either move to this destination object or return to its previous location. I've done various D-n-D tests and

How to set line spacing/height in a JLabel in Java Swing?

▼魔方 西西 提交于 2019-11-30 21:59:10
I have the following JLabel code: JLabel someJLabel = new JLabel("<html>first line<br>second line</html>"); someJLabel.setFont(new Font("Arial", Font.PLAIN, 16)); What I'd like to do is be able to control the line height/spacing between the two lines. PS: I've also looked at using paragraphs instead of breaklines, but it's the same thing. And I don't know if you can do that within an html tag without using css (you can't use css within html code in a JLabel in Java Swing). This should work, but it's not. color: green works though. content.add(new JLabel("<html><p style=\"line-height: 150%;\"