jlabel

How do I add a JLabel[] to a JTable?

有些话、适合烂在心里 提交于 2019-12-11 13:45:15
问题 I have an array of JLabels which I want to add to a JTable. I tried using myJTable.add(myJLabelArray); Hoping it would work, but it doesn't (Obviously, otherwise I wouldn't be here). Can somebody please help? 回答1: Using add method is not the way to add components to a JTable . Components should never be added directly to a JTable or its TableModel . JLabels are just Swing components that render text. You can use a TableCellRenderer . Have a look at Editors & Renderers 回答2: You cannot just add

JLabel does not update when using setText method

杀马特。学长 韩版系。学妹 提交于 2019-12-11 12:57:09
问题 In the project I am currently working on I have several pieces of information that I would like to make visible via Jlabel. There are a few buttons and textfields elsewhere in the GUI that allow for altering said information I would like to update the JLabel but the text never changes, or updates upon startup. I have attempted to use concurrency to update the labels, as suggested in other questions on this site, but I have had no luck with the labels updating. The concurrency does work with

JLabel retains previous text

笑着哭i 提交于 2019-12-11 11:59:59
问题 When spending a few minutes tweaking my desktop clock, I discovered a problem that I seem unable to resolve without help... I read some posts with similar problem but solutions did not work for me. The clock (in typical java form with an Action Listener and Calendar) works just fine. The intended tweak: To set the Frame, ContentPane and Label backgrounds to transparent so only the time/text shows . What happens is this: When the label background is transparent (or until it's opaque enough by

How can I output only a certain number of digits after a decimal place in a JTextComponent?

被刻印的时光 ゝ 提交于 2019-12-11 11:53:50
问题 I am using both JLabel s and JTextField s, and need to be able to truncate my doubles to two decimal places when they are displayed by the application. How can I perform this truncation, preferably without switching to JFormattedTextField s? 回答1: You can use DecimalFormat class. Here is an explanation 回答2: Prefer the Swing JFormattedTextField instead; see the Java Tutorial. 来源: https://stackoverflow.com/questions/2525492/how-can-i-output-only-a-certain-number-of-digits-after-a-decimal-place

Java - Changing A JLabel With Texts Stored in An Array

那年仲夏 提交于 2019-12-11 11:41:19
问题 Hello World, Am kinda new to java and i am trying to create a method that changes a JLabel's text to some text stored in an array when an action happens, somthing like this : JLabel one = new JLabel("Hello World"); JButton b1 = new JButton("Next"); JButton b2 = new JButton("Prev"); String[] main = ["LoveLace","Dynamics","Creed","Main"]; b1.addActionListsner(new ActionListener() { actionPerformed(ActionEvent e) { //In here it will load the first indexed string which is "Lovelace" //This is

Java resize an image

徘徊边缘 提交于 2019-12-11 11:14:57
问题 I would like to display an image in an area in my Jframe but the image takes up much space. I would like to take it fair precise dimensions. How can I do this in Java This is my simple code : I am open to any proposal if I did not use the right method or the right class to instantiate the image. import java.awt.*; import javax.swing.*; public class ExempleDeplace extends JFrame{ private JLabel myLabel; public ExempleDeplace(){ setLayout(new FlowLayout()); setTitle("Fenetre, modele Duchi");

How to add one image multiple times in one JFrame?

为君一笑 提交于 2019-12-11 10:23:16
问题 I am trying to make one image display multiple times. Here's part of my code: JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setBounds(30, 30, 800, 600); JLabel blue = new JLabel(new ImageIcon("blue.jpg")); JLabel green = new JLabel(new ImageIcon("green.jpg")); window.add(blue); window.add(green); window.add(blue); window.setLayout(new GridLayout(3, 3)); window.setVisible(true); Unfortunately what is created is just one image of each kind. What am

Refresh Image in JLabel with Timer

倾然丶 夕夏残阳落幕 提交于 2019-12-11 10:02:07
问题 I´m currently working on a little programm witch displays pictures from a website in a little Swing GUI. The Problem is, that every time the picture changes a new frame pops up instead of refreshing the JLable. I have no idea how to realize this after trying a few attempts with different methods. It would be nice if you could give me a little hint. import java.awt.BorderLayout; import java.awt.Image; import java.io.*; import java.net.MalformedURLException; import java.net.URL; import javax

How do you change label text in java after a timer ticks a second passed?

淺唱寂寞╮ 提交于 2019-12-11 09:36:54
问题 I have a timer with a delay of 5 seconds. I am trying to change the label named lblTimer after a second passes to act as a countdown. I am having issues with it as currently it only works at 5 seconds. Do you have any suggestionsuggestions? protected void Addition() { //addition function final int delay = 5000; //milliseconds ActionListener taskPerformer = new ActionListener() { @SuppressWarnings("unused") public void actionPerformed(ActionEvent evt) { //...Perform a task... frame

InputVerifier don't display each component icon(lable)

回眸只為那壹抹淺笑 提交于 2019-12-11 08:56:54
问题 I have a form that set a input verifier to it. I want when a user type a correct value for a text field and want to go to other text field, a check icon should be display besides of text field. But now in my code, when user type a correct value on first text field an go to other, Two icons displayed together! public class UserDialog extends JDialog { JButton cancelBtn, okBtn; JTextField fNameTf, lNameTf; JRadioButton maleRb, femaleRb; ButtonGroup group; JLabel fNameLbl, fNamePicLbl, lNameLbl,