jlabel

How to add an ImageIcon to a JFrame?

心已入冬 提交于 2019-11-27 07:10:27
问题 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

How to auto-adjust font size of multiple JLabel based on container size in a smooth way?

痞子三分冷 提交于 2019-11-27 06:57:10
问题 I need to resize the font of multiple JLabel based on the scaling factor used to resize the container. To do this, I am setting the font of each JLabel to null so that they take the font of the container. It works, but it also produces strange results. To be specific, the text seems to "lag" behind the container and sometimes it gets even truncated. I would like to avoid this behavior. Any idea how? Example code simulating the behavior: import java.awt.BorderLayout; import java.awt.Color;

Rotate JLabel or ImageIcon on Java Swing

懵懂的女人 提交于 2019-11-27 05:28:37
first of all, this is the first week that I use swing, then sorry if my question is too obvious. Also, I need solutions that use the standard java libraries, since this is for homework and I'm not allowed to use strange libraries. I'm using JLabel with ImageIcon to show images on a JFrame. Now I want to rotate the image on screen to arbitrary angles. I found something about Graphics2D but i don't find the way to do that. Since solutions that I found doesn't work or I don't understand them, I'm interested in any solution to rotate the ImageIcon or the JLabel. Since I'm positioning the image

.setBounds not working for JLabel and JButton

左心房为你撑大大i 提交于 2019-11-27 04:55:07
问题 I am trying to change the positioning of a JLabel and a JButton on my GUI. Even though I try to use .setBounds to change their locations; they both just appear in the top centre of the screen. import java.awt.color.*; import java.awt.font.*; import java.awt.Graphics; import java.awt.Image; import javax.swing.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; import javax.swing.UIManager.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; public class yo

How to format JLabel/JTextField so text wraps [duplicate]

余生颓废 提交于 2019-11-27 04:54:52
问题 This question already has answers here : Is there a “word wrap” property for JLabel? (6 answers) Closed 5 years ago . Lets say I have a string and JLabel, the JLabel displayed on a JFrame: public String content="Hello fellow stack-overflowers, I want to format this output"; public JLabel jL = new JLabel(); Once do the following: jL.setText(content); I get this output: Hello fellow stack-overflowers, I want to for.. But what I really want is the text not to keep going right past the length of

How to dynamically add JLabels to JPanel?

落爺英雄遲暮 提交于 2019-11-27 04:51:30
问题 I'm having a problem with this. I have a JPanel and normally I would create a JLabel like this: JLabel lblNewLabel = new JLabel("New label"); lblNewLabel.setBounds(0, 0, 135, 14); panel.add(lblNewLabel); but I want each time I click a button, in that panel to be created a new JLabel with the same size, but with a different height possition. I tried: panel.add(new JLabel(stringName)); but this way I don't get to set it's bounds. stringName I get from a JTextField. 回答1: First off, use a layout.

Swing JLabel text change on the running application

僤鯓⒐⒋嵵緔 提交于 2019-11-27 04:36:59
问题 I have a Swing window which contains a button a text box and a JLabel named as flag. According to the input after I click the button, the label should change from flag to some value. How to achieve this in the same window? 回答1: import java.awt.*; import javax.swing.*; import javax.swing.border.*; import java.awt.event.*; public class Test extends JFrame implements ActionListener { private JLabel label; private JTextField field; public Test() { super("The title"); setDefaultCloseOperation(EXIT

access to variable within inner class in java

孤者浪人 提交于 2019-11-27 03:12:26
问题 I'm trying to create an array of JLabels, all of them should go invisible when clicked. The problem comes when trying to set up the mouse listener through an inner class that needs access to the iteration variable of the loop used to declare the labels. Code is self-explanatory: for(int i=1; i<label.length; i++) { label[i] = new JLabel("label " + i); label[i].addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { label[i].setVisible(false); // compilation error here }

Java swing: Multiline labels? [duplicate]

丶灬走出姿态 提交于 2019-11-27 03:01:21
问题 This question already has answers here : Closed 6 years ago . 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:

How to make Circle image Label in Java?

天大地大妈咪最大 提交于 2019-11-27 03:01:09
问题 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... 回答1: 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