jlabel

Set dynamic JLabel text in a JDialog by timer

为君一笑 提交于 2019-12-02 03:27:42
Im trying to make a JDialog that will show the user a dynamic message on a JLabel. The message should be a count from 1 to 10 (and it should be changing a number every second). the thing is , when im debugging it - it's stops right after the "dia.setVisible(true);" , and will not proceed unless i will close the JDialog . is there any possible way of fixing it? Thanks. Take a look at the code : @Override public void run() { dia = new JDialog(parentDialog, true); dia.setLocationRelativeTo(parentFrame); String text = "Text "; dia.setSize(300, 150); jl = new JLabel(text); dia.getContentPane().add

extending BufferedImage

廉价感情. 提交于 2019-12-02 03:12:52
Why does the following code show a black image instead of the picture? How to properly extend BufferedImage? class SizeOfImage { public static void main(String[] args) throws Exception { URL url = new URL("http://cloudbite.co.uk/wp-content/uploads/2011/03/google-chrome-logo-v1.jpg"); final BufferedImage bi = ImageIO.read(url); final String size = bi.getWidth() + "x" + bi.getHeight(); final CustomImg cstImg = new CustomImg(bi.getWidth(), bi.getHeight(), bi.getType()); SwingUtilities.invokeLater(new Runnable() { public void run() { JLabel l = new JLabel(size, new ImageIcon(cstImg),

How to show/hide an image attached to a Jlabel after a Jbutton is clicked?

时光怂恿深爱的人放手 提交于 2019-12-02 02:43:18
问题 I'm new to programming world, and I need some help. I will try to be as clear as possible. This is my current situation: I'm programming a simple game. On a Jframe, I've added a Jlabel on which I attached an image. I've also added a Jbutton on the Jframe. I would like that when I click on the Jbutton, the image appears and on the next click the image hides. How could I do it? Thanks in advance and excuse me for the possible english mistakes. EDIT Following some instructions given by people, I

Java. Drag & Drop ImageIcon from JLabel on panel 1, to JLabel on panel 2. Add Counter function

假如想象 提交于 2019-12-02 02:36:57
I've implemented this very basic, drag and drop between two JPanels, but this doesn't really meet my requirements! public class test extends JFrame { { JPanel mainpanel, storypanel, imageselect; public test(){ mainpanel = new JPanel(new BorderLayout()); storypanel = new JPanel(); imageselect = new JPanel(); MouseListener listener = new MouseAdapter(){ public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; int j = 0; BufferedImage myImages; JLabel imgselect = new

Java move jlabel in animation every 0.5 second

空扰寡人 提交于 2019-12-02 02:15:57
I want simple animation to set location every 0.5 second but it doesnt animate only set location at the end of the loop. int x=1; int y=1; while(x<100){ jLabel1.setLocation(x, y); x=x+10; y=y+10; try{Thread.sleep(500);}catch(InterruptedException e){} } I have tried drawing animation with thread.sleep() and it worked, it was animated correctly but unfortanly that is not option for me as i need to move jlabel around frame wich has figure picture inside it. Can someone pls help me with this problem. i have tried with this two same result jLabel1.setBounds(x, y, jLabel1.WIDTH,jLabel1.HEIGHT); /

How to show/hide an image attached to a Jlabel after a Jbutton is clicked?

馋奶兔 提交于 2019-12-02 01:29:38
I'm new to programming world, and I need some help. I will try to be as clear as possible. This is my current situation: I'm programming a simple game. On a Jframe, I've added a Jlabel on which I attached an image. I've also added a Jbutton on the Jframe. I would like that when I click on the Jbutton, the image appears and on the next click the image hides. How could I do it? Thanks in advance and excuse me for the possible english mistakes. EDIT Following some instructions given by people, I've reached this point: button.addActionListener(new Actionbox()); final class Actionbox implements

How would I get the text of a JLabel (with an icon) explaining what the label is by hovering over the label?

荒凉一梦 提交于 2019-12-02 00:56:51
问题 I want to see the text of JLabel when I hover over the label. The text explains what the label does in detail. 回答1: You would need to set the text of the tooltip by calling: setToolTipText() More about tooltips in the tutorial: http://download.oracle.com/javase/tutorial/uiswing/components/tooltip.html 回答2: If you want to retrieve the Tooltip then you should use something like this: JLabel label; ...//initialize label, etc String text = label.getToolTipText(); In case you are asking how to set

Alignment issue in GridBagLayout

廉价感情. 提交于 2019-12-01 23:57:48
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TestForm extends JFrame { private JLabel heightLabel, weightLabel, waistLabel, neckLabel, hipsLabel,bfPercentageLabel; private JTextField heightTxt, weightTxt, waistTxt, neckTxt, hipsTxt; private JPanel centerPanel; private JPanel southPanel; private JLabel endTargetWeightLabel; private JLabel endTargetWeightResultLabel; private JLabel fatMustLoseLabel; private JLabel fatMustLoseResultLabel; public TestForm() { //Declaring instance variables heightLabel = new JLabel("Height:

Image won't display in JLabel

江枫思渺然 提交于 2019-12-01 23:08:08
问题 I've gone through every post I could find on this site and the Java tutorials and I still can't figure out why my code isn't working. Even when I copy/paste other peoples' code, it still doesn't work. I've made a dummy program just to test this out and the code looks like so: import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.ImageIcon; public class gui extends JFrame { private

Multiline JLabels - Java [duplicate]

南笙酒味 提交于 2019-12-01 22:34:18
问题 This question already has answers here : Multiline text in JLabel (9 answers) Closed 4 years ago . I want JLabel text in multiline format otherwise text will be too long. How can we do this in Java? 回答1: If you don't mind wrapping your label text in an html tag, the JLabel will automatically word wrap it when its container's width is too narrow to hold it all. For example try adding this to a GUI and then resize the GUI to be too narrow - it will wrap: new JLabel("<html>This is a really long