jlabel

How to resize Image/IconImage in JLabel?

拟墨画扇 提交于 2019-12-07 12:58:22
问题 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? 回答1: 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(

Why isn't this int incrementing?

牧云@^-^@ 提交于 2019-12-07 08:36:25
I am stuck on probably an easy problem, but I really can't find why it isn't working. I am trying to increase mijnScore with 1 each time the method gets called. But somehow mijnScore goes back to 0 after the method is done. int mijnScore = 0; ... public void updateUI() { System.out.println("updateUI"); SwingUtilities.invokeLater(new Runnable() { public void run() { ikWin = true; while(ikWin) { mijnScore++; System.out.println("mijnScore" + mijnScore); Scoresp1.setText(mijnScore + ""); ikWin = false; positie = 0; } } }); } Solved Making the variable static solved my problem. static int mijnScore

The Jlabel component disappeared from my Netbeans's palette

廉价感情. 提交于 2019-12-07 07:28:45
问题 I've been working on netbeans, coding some Java, and while designin a Jframe, I can't find the JLabel component on my Palette: image : http://img15.hostingpics.net/pics/524059label.png Where can I get it back please? 回答1: Right-click on the header Swing Controls in your palette Select Properties In the Dialog, open the tree node Swing Controls Select the Label check box Close 回答2: In my version of Netbeans 7.4 you do this instead: Right-click on the header Swing Controls in your palette

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

与世无争的帅哥 提交于 2019-12-07 07:14:44
问题 This question already has answers here : How do I present text vertically in a JLabel ? (Java 1.6) (5 answers) Closed 6 years ago . 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? 回答1: You could use the class VerticalLabelUI created by a dev: http://tech.chitgoks.com/2009/11/13/rotate-jlabel-vertically/ 回答2: You can create a method that will transform your text into an HTML code like this: public

JLabel ToolTip interferes with MouseListener

泪湿孤枕 提交于 2019-12-07 01:54:16
问题 I have Java Swing application ToolTipMouseTest The critical line is label.setToolTipText("label" + i); . Once it is commented out very click on a label produces 2 mousePressed in console. With this line enabled click on labels would produce nothing. Is this expected behaviour or a bug? My goal is to show tooltips without disabling MouseListener from working. Almost SSCCE, but without imports: public class ToolTipMouseTest { public static void main(String[] args) { SwingUtilities.invokeLater

Two icons in a JLabel?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 19:50:15
问题 I have an icon in a JLabel as shown below: Is it possible to add another icon (e.g. a flag representing a country) between the color icon and the text? For example, I want to add an icon depicting the U.S. flag between the red icon and US . Thanks! 回答1: Yes, use nested JLabel with BoxLayout in the container label: JLabel container = new JLabel(); container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS)); JLabel icon1Label = new JLabel(); JLabel icon2Label = new JLabel(); icon1Label

Adding text to a label from another class - Simple Logic Issue

前提是你 提交于 2019-12-06 16:35:30
I have a label and a button in a class called FrameTest , when i press the button, a method named buttonpressed get's executed from the class Test . In this buttonpressed method i will set a text to the label found in the FrameTest class. The problem i have is that, the text for the label is not getting set. The reason is that i am creating a separate object to call the buttonpressed method; public void actionPerformed(ActionEvent arg0) { Test t = new Test(); t.buttonpress(); } and i am creating a separate object in the main method of the Test class to create the UI. public static void main

which JLabel has been clicked?

寵の児 提交于 2019-12-06 15:07:59
问题 I have 6 JLabel and each is having a different instance of a mouselistener class attached. How to know which JLabel has been clicked ? These JLabel form a two dimentional array. 回答1: You use getSource to get a refrence to the object which is clicked on: label1.addActionListener(new yourListener()); label2.addActionListener(new yourListener()); public class yourListener extends MouseAdapter{ public void mouseClicked(MouseEvent e){ JLabel labelReference=(JLabel)e.getSource(); labelReference

ArrayList content to JLabel

为君一笑 提交于 2019-12-06 14:58:38
If i have an ArrayList of type Integer, containing numbers like 1,3,4,9,10 etc... How can i display those on a JLabel, not the sum, but all the numbers in a sequence. So the JLabel would display, in this case: 134910 Thank you in advance for any help. EDIT: Thank you all, ofcourse i should have thought about append. Anyways, thanks all! Like this: StringBuilder sb = new StringBuilder(); for (Integer i : list) { sb.append(i == null ? "" : i.toString()); } lbl.setText(sb.toString()); private static String fromListToString(List<Integer> input) { StringBuilder sb = new StringBuilder(); for

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

此生再无相见时 提交于 2019-12-06 14:57:30
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 buttons) What I'm looking to achieve is for the buttons position to never move, and to put the text under