jlabel

How to add fade/fade out effects to a JLabel

旧城冷巷雨未停 提交于 2019-11-28 12:58:24
Hello I am trying to create a Java game and need to add some effects to my label. I have the following questions How to add fade in/ fade out effects to my label . I have a JLabel but I need a shape for it, possibly a rectangle or a cloud shape . How can I get that done ? You can use a AlphaComposite to change the opactiy level of a component... Now, with a little clever use of a timer, you can make the label fade in and out or simply control the opacity as you please... public class TestFadeLabel { public static void main(String[] args) { new TestFadeLabel(); } public TestFadeLabel() {

How to make draggable components with ImageIcon

吃可爱长大的小学妹 提交于 2019-11-28 12:55:42
I'm trying to build a user interface for a chess game. I've used a GridBagLayout filled with JLabels and the chess pieces are ImageIcons of the JLabels . Now I would like to move the pieces by dragging it on the board. Is there a way to do this with ImageIcons ? Or is there a better way to solve the problem? EDIT: here is a sample code. you can notice that you can move the iconImage, but it doesn't "drag" with the mouse. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.GridBagConstraints;

Append text in JLabel

。_饼干妹妹 提交于 2019-11-28 12:42:52
How would I go about achieving the effect of JTextArea with JLabel? I want the output to be displayed every time the button is clicked on the next line down instead of replacing what text is already there, i.e. like an append method for JLabel? I just want it to follow the same behavior as JTextArea.append. Also I want to add hyperlink to each line. Use HTML formatting in the label by starting the text with prefix <html><body> (possibly add some in-line styles in the body opening element). Add each line, ending with <br> or <p> (or <li> if adding <ul><li> to the prefix). See also How to Use

How to add an ImageIcon to a JFrame?

旧城冷巷雨未停 提交于 2019-11-28 12:32:20
I'm trying to add an image to one frame but it seems it does not working. The image created by an ImageIcon from the specified file. The image file is in the seam directory the java file exist. import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class image { public static void main(String args[]) { TimeFrame frame = new TimeFrame(); } } class TimeFrame extends JFrame { //Image icon = Toolkit.getDefaultToolkit().getImage("me.jpg"); ImageIcon icon = new ImageIcon("me.jpg"); JLabel label = new JLabel(icon); public TimeFrame(){

Moving a view port over a larger image; JLablel+JScrollPane

旧街凉风 提交于 2019-11-28 09:57:10
问题 I have a JScrollPane m_jScrollPane with a JLabel m_jlImage being displayed inside of it. The m_jlImage is a screen capture with a red dot drawn where the user last clicked on the screen. I wish to move (read scroll) the viewing area of the m_jScrollPane over the red dot on the m_jlImage . lastClick is the last place the user clicked and is in the same coordinates as m_jlImage . This is proving to be more difficult that I thought. I decided to get the ratio of the click point's value to the

Underlined JLabel

不问归期 提交于 2019-11-28 09:39:29
I am trying to make a JLabel underlined. I searched everywhere, but I got nothing. Even in the properties, there is no option for underlining the JLabel. What can I do? Abdelrahman Wahdan JLabel label = new JLabel("<HTML><U>YOUR TEXT HERE</U></HTML>"); label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); OR JLabel label = new JLabel("Underlined Label"); Font font = label.getFont(); Map attributes = font.getAttributes(); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); label.setFont(font.deriveFont(attributes)); Reimeus JLabel label = new JLabel("Underlined Label

Java swing: Multiline labels? [duplicate]

风流意气都作罢 提交于 2019-11-28 09:34:58
Possible Duplicate: Multiline text in JLabel I want to do this: JLabel myLabel = new JLabel(); myLabel.setText("This is\na multi-line string"); Currently this results in a label that displays This isa multi-line string I want it to do this instead: This is a multi-line string Any suggestions? Thank you EDIT: Implemented solution In body of method: myLabel.setText(convertToMultiline("This is\na multi-line string")); Helper method: public static String convertToMultiline(String orig) { return "<html>" + orig.replaceAll("\n", "<br>"); } You can use HTML in JLabels . To use it, your text has to

How to make Circle image Label in Java?

旧城冷巷雨未停 提交于 2019-11-28 09:34:33
How to make Circle image Label in Java? I wanna make circle image Label But I can't do this.. Hey guys Help me..T.T I tried make circle panel for add image icon but that didn't work. help me please... MadProgrammer I think you should change your tack, instead of trying to modify the output of a component, instead, modify the input... So all this does, is apply a circular (alpha based) mask to another image BufferedImage master = ImageIO.read(new File("/Volumes/Disk02/Dropbox/MegaTokyo/thumnails/megatokyo_omnibus_1_3_cover_by_fredrin-d4oupef.jpg")); int diameter = Math.min(master.getWidth(),

HTML in JLabel not showing

雨燕双飞 提交于 2019-11-28 08:22:22
问题 JLabel label = new JLabel("<html><body>Hello world</body></html>"); shows nothing. If I get rid of the tags, it shows plain text (as expected), so the JLabel is definitely being added and shown on the window. Same for: JEditorPane jep = new JEditorPane("text/html", "<html><body>Hello world</body></html>"); Any ideas? I'm using java-6-openjdk with Eclipse. More details: matt@matt-laptop:~$ java -version java version "1.6.0_20" OpenJDK Runtime Environment (IcedTea6 1.9.5) (6b20-1.9.5-0ubuntu1

JLabel on top of another JLabel

拜拜、爱过 提交于 2019-11-28 07:58:00
问题 Is it possible to add a JLabel on top of another JLabel? Thanks. 回答1: The short answer is yes, as a JLabel is a Container, so it can accept a Component (a JLabel is a subclass of Component ) to add into the JLabel by using the add method: JLabel outsideLabel = new JLabel("Hello"); JLabel insideLabel = new JLabel("World"); outsideLabel.add(insideLabel); In the above code, the insideLabel is added to the outsideLabel . However, visually, a label with the text "Hello" shows up, so one cannot