jlabel

Code is getting displayed rather than components

跟風遠走 提交于 2019-12-12 20:19:19
问题 Please have a look at the following code import java.awt.GridLayout; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; public class TestSend

How to correctly update an Image in a JLabel?

被刻印的时光 ゝ 提交于 2019-12-12 19:26:28
问题 I'm French so my English is quite bad but I have a real problem with java: I'm trying to show an Image built manually with some fillRect & co. It works. Next, I want to update this image as a function of the text I enter in the text field. And there is the problem: it doesn't change anything, and if I manually rescale the window of the JFrame , the image shows totally deformed or scaled badly. I'm a beginner and I have difficulties with GUI, moreso when I want to couple it with Images. Can

Graphics on top of a Panel

百般思念 提交于 2019-12-12 19:21:42
问题 I am having trouble with the Graphics that I am drawing on a Panel which has a JLabel on top of it. I am using a custom paintComponent(Graphics g) method to draw a String on the Panel. I want the string to show on top of the JLabel instead of under the JLabel, which is what is currently happening. Here is the paintComponent method if you want to see it: public void paintComponent(Graphics g){ super.paintComponent(g); if(a.shouldAnnotate()){ FontMetrics size= g.getFontMetrics(); if(getWidth()>

Java project working on Eclipse but not working when exported to runnable jar file

試著忘記壹切 提交于 2019-12-12 17:19:28
问题 i am having a issue with exporting my java file to a runnable jar file. In the eclipse it works fine, but when i exported it, it doesn't work. I already tried the (java -jar MyJar.jar) to get the log but it says "Unnable to access the jar file" I think the problem is because of this: java.net.URL logoOneUrl = getClass().getResource("/logo.png"); //already tried without the "/" and it doesn't work withouth the "/" Icon logoOne = new ImageIcon(logoOneUrl) Because when i put it in comment //

Creating a JLabel with a Gradient

江枫思渺然 提交于 2019-12-12 15:01:16
问题 I'm new to Java and I'm trying to create a heading using a JLabel and for its fill to be a gradient. I cannot get it to work and I've been trying for a while. I've been grabbing bits of come from here and other websites and cannot seem to make this work, nor make sense of other peoples more complex code that does work. Here are my two classes so far: import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt

Loading Base64 Encoded Image String into JLabel

大憨熊 提交于 2019-12-12 12:30:47
问题 I got the converter working here public class ImageProcessor { public static void Base64TImage(String base64) { try { byte[] btDataFile = new sun.misc.BASE64Decoder().decodeBuffer(base64); File of = new File("yourFile.png"); FileOutputStream osf = new FileOutputStream(of); osf.write(btDataFile); osf.flush(); } catch (IOException ex) { Logger.getLogger(ImageProcessor.class.getName()).log(Level.SEVERE, null, ex); } } public static void main(String args[]){ String base64 =

JLabel with HTML does not set width properly

99封情书 提交于 2019-12-12 12:25:50
问题 I am trying to set the width of a JLabel using an HTML div tag. Consider the following code: import javax.swing.*; public class Xyzzy extends JFrame{ public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { Xyzzy frame = new Xyzzy(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.PAGE_AXIS)); String s = "x "; for (int i=0; i<200; ++i) s += "x "; JLabel jl = new

How can I make a countdown in my applet?

此生再无相见时 提交于 2019-12-12 10:27:25
问题 I'm writing a game and need a 60 second countdown. I would like it to start counting down when I click the "Start" button. I can get it to countdown manually right now, but need it to do so automatically. This is a Java Applet, not Javascript. Is there a way I can have this timer go in the background while I use other buttons? I'm using JLabels and JButtons. Can I have two ActionListeners running at the same time? 回答1: Use javax.swing.Timer Run this example. You will see that you can still

Why do cell renderers often extend JLabel?

让人想犯罪 __ 提交于 2019-12-12 08:33:40
问题 I noticed this is common. For example DefaultListCellRenderer, DefaultTableCellRenderer, and DefaultTreeCellRenderer all use it. Also a lot of the custom cell renderers I see online use this as well. I want to use a custom TableCellRenderer in my code, but I'm confused about whether I really need to subclass JLabel. What's the benefit of subclassing JLabel? 回答1: The API for the DefaultTableCellRenderer states: The table class defines a single cell renderer and uses it as a as a rubber-stamp

Java Swing JLabel, HTML and custom fonts

会有一股神秘感。 提交于 2019-12-12 07:37:57
问题 In our Java Swing application, we're loading a custom font and adding it to a JLabel : try { this.font = Font.createFont(Font.TRUETYPE_FONT, new File("resources/fonts/ourcoolfont.ttf")).deriveFont(16f); } catch (Exception e) { this.font = new Font("Arial", Font.PLAIN, 16); } this.label.setFont(this.font); Easy and worked fine on 3 different systems. Until someone else tried to run it. The font was loaded (as we're also using on some other Swing elements), but not used in the JLabel . After