jlabel

Swing dynamic(auto) fit-layouting

好久不见. 提交于 2019-12-23 05:48:22
问题 Considering 100(dynamic) JLabel Object, and I want to show them inside a resizable JPanel . Currently I use grid bag layout (2 columns and 50 rows), but when user resizes and expands the form, I want to have(for example) 4 columns and 25 rows, and same for small form(1 column, and 100 rows), in other way fill up the whole panel(no any white spaces). I know this is should be done manually, currently I redraw(repaint) all members once user resize the form, but I just was wondering if there is

How to move JButtons and JLabels position in a JPanel, JFrame

瘦欲@ 提交于 2019-12-23 03:38:15
问题 I am creating a simple lottery as a practice, I am a beginner of Java. I have achieved almost everything that I want apart from one thing: Moving the different texts and buttons to the position that I'd like them to be. Here is a picture edited in Photoshop describing how I would like it to be: The Lottery currently looks like this after you press the Play button: (As you can see the buttons get shifted to the right in order to make space for the text that is squished in to the left of the

Showing part of an ImageIcon

南笙酒味 提交于 2019-12-23 03:12:22
问题 Bonjour, I'm trying my hand at animation, and have found myself a strip of explosions on a single image in a row. I want them to show one after the other in sequence to animate an explosion. Naturally, I'm thinking ImageIcon on JLabel , but when I looked at the JLabel spec I found this line: JLabel(Icon icon) -- Creates a JLabel instance with the specified image. The label is centered vertically and horizontally in its display area. I want to be able to show only part of a full image in the

Showing part of an ImageIcon

送分小仙女□ 提交于 2019-12-23 03:12:06
问题 Bonjour, I'm trying my hand at animation, and have found myself a strip of explosions on a single image in a row. I want them to show one after the other in sequence to animate an explosion. Naturally, I'm thinking ImageIcon on JLabel , but when I looked at the JLabel spec I found this line: JLabel(Icon icon) -- Creates a JLabel instance with the specified image. The label is centered vertically and horizontally in its display area. I want to be able to show only part of a full image in the

Dynamically change the width of JDialog

让人想犯罪 __ 提交于 2019-12-22 18:42:33
问题 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! 回答1: getPreferredSize for JLabel - basically you have to get textLength from JLabel in pixels, there are 3 correct ways,

I want to decrease the font size if text doesn't fit in JLabel

半腔热情 提交于 2019-12-22 10:58:50
问题 There were many posts regarding this problem, but i couldn't understand the answers given by people in there. Like in this post: "How to change the size of the font of a JLabel to take the maximum size" the answer converts the font size to 14! But that is static and further in other answers; their whole output screen seems to increase. I display certain numbers in a JLabel named "lnum", it can show numbers upto 3 digits but after that it shows like "4..." I want that if the number is able to

How to change JLabel font size to fill JPanel free space while resizing?

怎甘沉沦 提交于 2019-12-22 07:01:05
问题 There is a similar question here: How to change the size of the font of a JLabel to take the maximum size but it doesn't work in backwards. So if you make JPanel bigger, font is growing, but if you make it smaller JLabel size and font remain as before Check this Image How to make Jlabel font growing according to JPanel size while resizing? 回答1: by using FontMetrics and TextLayout you can get this output (please read an comment in the code) SwingUtilities can do that correctly too I sugget to

Java align JLabel in center of JPanel

安稳与你 提交于 2019-12-22 05:24:39
问题 I have a bar at the top of my application that has a number of buttons either side of a JLabel. The button's visibility is dependent upon the current task a user is carrying out and one of the button's text may also change depending on the current state. What I would like to do is have a number of buttons stick to the left of the JPanel, the JLabel's center to be in the very center of the JPanel and the rest of the buttons to be to the right of the JPanel. So far I have managed to get the

JLabel hyperlink to open browser at correct URL

社会主义新天地 提交于 2019-12-22 03:48:11
问题 I need to create a label with Java Swing that is clickable and able to open the default browser on the desktop and redirect it to a specific url. My code is able to open up the browser but not redirecting it to the correct url (the default home page is loaded). My test code: import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.IOException; import java.net.*; public class LinkTest extends JFrame { public LinkTest() { JPanel p = new JPanel(); JLabel link = new JLabel

JLabel and JLayeredPane - How to display an image over another image?

拜拜、爱过 提交于 2019-12-21 05:16:10
问题 I try to create a little game in java but I'm in trouble. When I draw a map, I'm not able to display the characters without overwrite the titlesets of the squares. My goal is to be able to display many pictures on the same square (like the titleset of the grass, the character and a tree), so I have to deal with the transparency of my pictures (this is not the problem) and the layer (it is the problem). So how can I display an image on another image? How can I explain to java that I need to