jlabel

Updating a rotated JLabel using Graphics2D causes old and new text to merge together

馋奶兔 提交于 2019-12-11 18:22:56
问题 I am trying to rotate a JLabel 90 degrees that shows the current time 90 degrees. After doing some research, most people have recommended using Graphics2D and AffineTransform. This almost works, but when the minute in the time is updated, the new digit appears to merge with the old digit. This does not happen for the seconds. Does anybody have any idea how to fix this issue or have an alternate solution? Driver class: import java.awt.Color; import java.awt.Dimension; import java.awt

how to highlight part of a JLabel at runtime?

一笑奈何 提交于 2019-12-11 18:19:38
问题 I have a JLabel inside a JPanel. I'm using Netbeans IDE for the GUI of my java program (free design, and no Layout Manager). At runtime I need to highlight a part of my JLabel. Highlighting a part of JLabel can be done as said here : How to highlight part of a JLabel? I don't know how to do that in run time, I mean I already have a JLabel, now how can I override it's paintComponent() method for that purpose ? 回答1: Here is an illustrative example of the answer given by Tikhon Jelvis in the

Beginner Java Netbeans: How do I display for loop in jlabel?

那年仲夏 提交于 2019-12-11 18:14:52
问题 I have looked on this site and nothing has really answered my question. This is what my code looks like: // declare user input variables int min, max; //assign user input to min and max min = Integer.parseInt(Min.getText ()); max = Integer.parseInt(Max.getText ()); //use for loop to display the values for (int n = min; n<= max; n++){ System.out.println(Integer.toString(n)); Output.setText(Integer.toString(n)); } and the System.out.println () yields the correct answer. for instance, the user

Adding a JLabel in relative position to buttons

我的梦境 提交于 2019-12-11 18:14:44
问题 OK, this is the relative code I have so far. for (int i = gameLines - 1; i > 0; i--) { for (int j = 0; j < i; j++) { JButton jButton = new JButton(); jButton.setSize(buttonWidth, buttonHeight); jButton.setText("" + line[i].charAt(j)); int x = ((buttonWidth / 2 * gameLines + 1) - (buttonWidth / 2 * i) + (buttonWidth * j)); int y = (gameLines - (i + 1)) * buttonHeight; jButton.setLocation(x, y); panel.add(jButton); button[i][j] = jButton; button[i][j].setActionCommand(Integer.toString(i) + "."

JLabels, that store ImageIcons, are returned back to original location when the mouse is clicked in the panel

戏子无情 提交于 2019-12-11 18:07:36
问题 I've added this listener to a JLabel, and I am able to drag the image around perfectly, However, as soon as I click on the panel(in an area where a JLabel is not present) the label returns back to it's original location. I can't figure out why that would happen. Please help me out, I've spent hours working on this. Thanks! public class CardLabelListener extends MouseAdapter { private MouseEvent initiateEvent = null; @Override public void mouseReleased(MouseEvent me) { System.err.println(

Move and Reorder JLabels in JPanel using DnD

ぐ巨炮叔叔 提交于 2019-12-11 16:19:41
问题 I have a program I'm working on that takes input names and creates JLabels and populates them into an ArrayList. When the user clicks the Begin button, the JLabels populate in the left JPanel. What I've been trying to do it use DnD to allow the user to drag and re-order the labels in the left panel. So far, I've only been able to get it to copy the text from one label to another. My goal is to drag a label up or down in the list, and depending on where it's dropped in the JPanel, have the

Why isn't setText updating the JLabel?

拟墨画扇 提交于 2019-12-11 14:58:39
问题 I've checked on the other threads here and haven't found a solution. 1) The JFrame is setVisible(true). 2) What does this mean: "I wonder if your problem is a concurrency issue, that you are doing a long-running process on the Swing event thread and that this is preventing your label from updating its text." I read that somewhere else. 3) I haven't initialized multiple times the JPanel that contains the label. EDIT: 4) updateTurn is called from the JPanel that contains TrackingPanel (i.e.

Multi line label/area/pane in Java with Justified text [closed]

拜拜、爱过 提交于 2019-12-11 14:35:39
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I have an interesting task. Consider a String content with unknown length. I'd like to display content with a Font font with Justified text. I need to know what height this would take up if I specify the width .

Rendering Image into label

a 夏天 提交于 2019-12-11 14:25:22
问题 I have a label. I want to render image into it. But the following code would do anything. CardLayout cl = (CardLayout) (mainPanel.getLayout()); cl.show(mainPanel, "newPersonaCard"); BufferedImage myPicture = ImageIO.read(new File("C:\\Desktop\\Documents\\Pictures\\always.jpg")); ImageIcon icon = new ImageIcon(myPicture); icon.getImage().flush(); I am using netbean designer. 回答1: You are right, in some cases there issue with repainting Icon in the JLabel , then you have to call, myIcon

I'm trying to set JTextField under JLabel

与世无争的帅哥 提交于 2019-12-11 14:06:26
问题 I'm trying to put the text field under the JLabel . Currently, the text field is displayed on the same line. It should be below and centered. I need assistance. package Gui; import javax.swing.*; import java.awt.*; import java.awt.GridLayout; public class ShowGridLayout extends JFrame { public ShowGridLayout() { // Set GridLayout, 3 rows, 2 columns, and gaps 5 between // components horizontally and vertically setLayout(new GridLayout(3, 2, 5, 5)); // Add labels and text fields to the frame