jlabel

What causes poor image quality in Java JLabel icons?

微笑、不失礼 提交于 2020-05-09 02:22:58
问题 Java JLabel icons are displaying with distorted pixels in JFrame . This is happening consistently with different png images (all 32x32). I am not scaling the images, they are displayed in the program 32x32, which I verified using getWidth and getHeight on the JLabel. The distortions appear in the same place each time the program is run, not randomly. Screenshot using the example code provided below. In this screenshot you can see an array of JLabel icons, each affected one differently. When

Java Swing applicaion gif animation leaving a trail

五迷三道 提交于 2020-03-25 17:51:12
问题 Hey all I am wondering if I can fix my animation issue. Currently it does animate just fine but with one issue - it seems to leave training images behind as it animates. This is my code I am using: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Point; import java.awt.RenderingHints; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event

Java JTextArea KeyListener

十年热恋 提交于 2020-02-27 06:19:09
问题 When I pressed the ENTER my JTextArea starts a new row and I only want do to the doClick() method nothing else. How should I do that? textarea.addKeyListener(new KeyListener(){ @Override public void keyPressed(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_ENTER){ button.doClick(); } } @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } }); 回答1: Use .consume() : Consumes this event so that it will not be processed in the default manner by the source

Java JTextArea KeyListener

跟風遠走 提交于 2020-02-27 06:19:06
问题 When I pressed the ENTER my JTextArea starts a new row and I only want do to the doClick() method nothing else. How should I do that? textarea.addKeyListener(new KeyListener(){ @Override public void keyPressed(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_ENTER){ button.doClick(); } } @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } }); 回答1: Use .consume() : Consumes this event so that it will not be processed in the default manner by the source

Updating a JLabel within a JFrame

爱⌒轻易说出口 提交于 2020-02-15 06:52:19
问题 I've been searching around this site and the internet for hours trying to figure out how to fix this problem. I'm creating a game and it's my first time using graphics. I figured out how to create a JFrame, JPanel and JLabel, and the only problem I can't seem to get around is updating the JLabel. Let's say I start it out like this: JLabel testing = new JLabel ("blah", JLabel.CENTER); testing.setAlignmentX(0); testing.setAlignmentY(0); frame.add(testing); I am able to change the text after a

Unable to remove JLabel from JPanel after adding programmatically

て烟熏妆下的殇ゞ 提交于 2020-01-30 07:58:49
问题 I have a class called LMSPanel that extends JPanel . This class has the two following methods: /** * A method to add an informative temporary label to the Panel until * the second Sensor is added. * * @param zoneid - The ID of the Zone. * @param sensorid - The ID of the Sensor. */ public void justAddedLbl(String zoneid, String sensorid) { infoLbl = new JLabel("Sensor: " + zoneid + sensorid + " added. Please Add 2nd Sensor."); add(infoLbl); revalidate(); } /** * A method to remove the

Unable to remove JLabel from JPanel after adding programmatically

我怕爱的太早我们不能终老 提交于 2020-01-30 07:58:31
问题 I have a class called LMSPanel that extends JPanel . This class has the two following methods: /** * A method to add an informative temporary label to the Panel until * the second Sensor is added. * * @param zoneid - The ID of the Zone. * @param sensorid - The ID of the Sensor. */ public void justAddedLbl(String zoneid, String sensorid) { infoLbl = new JLabel("Sensor: " + zoneid + sensorid + " added. Please Add 2nd Sensor."); add(infoLbl); revalidate(); } /** * A method to remove the

How to remove a JButton in a JButton matrix?

故事扮演 提交于 2020-01-25 14:16:55
问题 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

How to remove a JButton in a JButton matrix?

十年热恋 提交于 2020-01-25 14:15:10
问题 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

How to remove a JButton in a JButton matrix?

风流意气都作罢 提交于 2020-01-25 14:13:23
问题 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