jlabel

How to remove a JButton in a JButton matrix?

一世执手 提交于 2020-01-25 14:13:18
问题 I want to remove a certain botton using MouseListener from a matrix of bottons and add a JLabel in the empty, so I use: import java.awt.*; import java.awt.event.*; import javax.swing.*; public MyClass(){ object = new Object(); bottons = new JButton[5][5]; labels = new JLabel[5][5]; myPanel = new JPanel(); myPanel.setLayout(new GridLayout(5,5)); click =false; for(int i = 0 ; i<5 ; i++){ for(int j = 0; j<5 ; j++){ myPanel.add(bottons[i][j] = new JButton()); } } } public void mouseReleased

No J components show on my shape?

喜欢而已 提交于 2020-01-25 03:41:12
问题 I'm having a really big issue in which when ether I create a JLabel, Jbutton and so on....it works in terms of showing on screen however when I want to place them on a rectangle it disappears and the rectangle only shows? With JLabel I opted to use drawstring instead but now I'm stuck with trying to get JTextField on. I don't know what I am missing. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.*; import javax.swing.event.*; class main { public static void

Anti-aliased JLabel

我怕爱的太早我们不能终老 提交于 2020-01-24 10:50:07
问题 I've attempted to create a custom anti-aliased JLabel , but my text remains rigid. Why doesn't this work? The answers to similar questions include more verbose solutions, but I want to know why this isn't working. Edit: Here's an SSCCE: import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JFrame; import javax.swing.JLabel; public class Tester { public static void main(String[] args) { SmoothLabel label = new SmoothLabel

Retrieve Image From JLabel and store it in a variable in Java

旧街凉风 提交于 2020-01-23 17:48:30
问题 How do I retrieve an my image that has been fetched from mysql database and store it in a variable? The image retrieved from the database is as follows: byte[] imageData = rs.getBytes("Image"); format = new ImageIcon(imageData); lblimg.setIcon(format); Now what I want to do, to store the lblimg into a variable. Then I can use the variable which contains the image to add in a pdf file. Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream("Report.pdf")); doc.open();

Swing/Java: How to use the getText and setText string properly

吃可爱长大的小学妹 提交于 2020-01-21 07:01:30
问题 I'm trying to make input nameField appear in a Label called label1 after a Button called button1 is clicked. Right now it says: 'txt' and I understand why. But I don't know how I can use the string! Can anyone explain me what I'm doing wrong and how to use this string properly? import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel;

Java JLabel, break text to next line?

折月煮酒 提交于 2020-01-21 06:37:19
问题 It's been awhile since I asked a question! I'm developing an application in Java where JLabels are used. Anyway, as you may or may not be able to see from the picture below, the text that says Category Test gets cut off and ends up saying Categor... instead. Is there any way that I can "break" the text once it fills up the width of the label? Here is the image: What I did I used a JTextPane like so: JTextPane text = new JTextPane(); SimpleAttributeSet attr = new SimpleAttributeSet();

how to put a JLabel inside a JLabel or divide a JLabel into squares

本秂侑毒 提交于 2020-01-19 04:04:23
问题 I have created a snake and ladder game and it works well, but now I want to add a little bit modification to it. I want each player to have two pieces/players instead of one. The new rule now becomes, two pieces of the same player can occupy the same square, hence I need a way to show them in the same square. I used JLable to identify each square, but now I want each square to hold more than one piece. That is, if a square is occupied by more than one piece the user must be able to click on a

Spacing issues when print monospaced font - Existing java bug 6784397

微笑、不失礼 提交于 2020-01-15 12:32:45
问题 I know there are a few other posts regarding this, but none of the solutions seem to have worked for me. I have an issue in Java 1.6 with printing monospaced font. The spaces between words get messed up. This is an existing Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6784397 I am trying to print a bunch of JLabels which all contain monospaced font text. I tried to apply the workaround described in the bug ticket (i.e using FontDesignNetrics). However, the workaround only

Refreshing a JPanel-Moving a JLabel

懵懂的女人 提交于 2020-01-15 11:28:06
问题 I am having trouble moving this JLabel across this JPanel? I put the code below. Basically what is supposed to happen, is the JLabel called "guy" slowly moves to the right. The only problem is, that the JLabel isn't refreshing it just disappears after the first time I move it. public class Window extends JFrame{ JPanel panel = new JPanel(); JLabel guy = new JLabel(new ImageIcon("guy.gif")); int counterVariable = 1; //Just the constructor that is called once to set up a frame. Window(){ super(

Adding an Image to JPanel using NetBeans IDE

為{幸葍}努か 提交于 2020-01-15 10:13:08
问题 I am trying to add n image to a panel using Netbeans. I dragged a Panel from the palette on to the frame and sized it according to what I want the image size to be. In the constructor I then added the image to the panel(I named it panelImage) like this. JLabel label = new JLabel(new ImageIcon("images\\BrokenFrameResized.jpg")); paneImage.add(label); The image however does not display. What is the best way to have the an image displayed as the size of the Panel using Matisse layout manager(i.o