jlabel

JLabel only shows if initComponents() is deleted

你。 提交于 2019-12-02 09:35:36
MainFrame.java -JFrame public MainFrame() { initComponents(); Letters pl = new Letters(this); this.setContentPane(pl); this.setTitle("Preset Lessons"); this.pack(); } Letters.java -JPanel public Letters(JFrame frame) { initComponents(); JLabel label = new JLabel(); label.setText("Sample"); this.add(label); } if initComponents() in Letters.java is deleted thats the only time the JLabel will show up. How can I put the new JLabel to my existing JPanel? Contents of Letters.java's initComponents(); if I removed the iniComponents in the constructor it will create the JLabel. private void

Why instance of JLabel shows only 8 lines?

六月ゝ 毕业季﹏ 提交于 2019-12-02 08:44:18
Here's the code snippet: import java.awt.BorderLayout; import java.awt.HeadlessException; 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.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.ScrollPaneConstants; /** * * @author mohammadfaisal * http://ermohammadfaisal.blogspot.com * http://facebook.com/m.faisal6621 * */ public class CodeMagnets extends JFrame{ private JTextArea area4Label; private JLabel codeLabel; private JButton

Using an image for the background of a JPanel and JButton

拜拜、爱过 提交于 2019-12-02 08:37:00
I am trying to use an image I made in photoshop as the background for my GUI. How do I do that? also I made some images I want to display in the button backgrounds after the action is performed... For the JButton, use this: JButton button = new JButton("Button Name", new ImageIcon("foo.png"); The Panel is a bit more interesting. This is a good method, though: ImagePanel panel = new ImagePanel(new ImageIcon("foo.png").getImage()); 来源: https://stackoverflow.com/questions/8373006/using-an-image-for-the-background-of-a-jpanel-and-jbutton

proplem in updating JLabel in for loop

自作多情 提交于 2019-12-02 07:47:53
The idea of my program is to select one name from a list that saved before in other JFrame. I'd like to print in the label all names one after the other with small delay between them, and after that stop at one of them. The problem is that lbl.setText("String"); doesn't work if there is more than one setText code. Here is the part of my code : public void actionPerformed(ActionEvent e) { if (RandomNames.size != 0) { for (int i = 0; i < 30; i++) { int rand = (int)(Math.random() * RandomNames.size); stars.setText(RandomNames.list.get(rand)); try { Thread.sleep(100); } catch (InterruptedException

extending BufferedImage

一个人想着一个人 提交于 2019-12-02 07:09:45
问题 Why does the following code show a black image instead of the picture? How to properly extend BufferedImage? class SizeOfImage { public static void main(String[] args) throws Exception { URL url = new URL("http://cloudbite.co.uk/wp-content/uploads/2011/03/google-chrome-logo-v1.jpg"); final BufferedImage bi = ImageIO.read(url); final String size = bi.getWidth() + "x" + bi.getHeight(); final CustomImg cstImg = new CustomImg(bi.getWidth(), bi.getHeight(), bi.getType()); SwingUtilities

Java move jlabel in animation every 0.5 second

Deadly 提交于 2019-12-02 05:47:10
问题 I want simple animation to set location every 0.5 second but it doesnt animate only set location at the end of the loop. int x=1; int y=1; while(x<100){ jLabel1.setLocation(x, y); x=x+10; y=y+10; try{Thread.sleep(500);}catch(InterruptedException e){} } I have tried drawing animation with thread.sleep() and it worked, it was animated correctly but unfortanly that is not option for me as i need to move jlabel around frame wich has figure picture inside it. Can someone pls help me with this

Java. Drag & Drop ImageIcon from JLabel on panel 1, to JLabel on panel 2. Add Counter function

∥☆過路亽.° 提交于 2019-12-02 05:39:34
问题 I've implemented this very basic, drag and drop between two JPanels, but this doesn't really meet my requirements! public class test extends JFrame { { JPanel mainpanel, storypanel, imageselect; public test(){ mainpanel = new JPanel(new BorderLayout()); storypanel = new JPanel(); imageselect = new JPanel(); MouseListener listener = new MouseAdapter(){ public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler

Alignment issue in GridBagLayout

混江龙づ霸主 提交于 2019-12-02 05:03:18
问题 Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TestForm extends JFrame { private JLabel heightLabel, weightLabel, waistLabel, neckLabel, hipsLabel,bfPercentageLabel; private JTextField heightTxt, weightTxt, waistTxt, neckTxt, hipsTxt; private JPanel centerPanel; private JPanel southPanel; private JLabel endTargetWeightLabel; private JLabel endTargetWeightResultLabel; private JLabel fatMustLoseLabel; private JLabel

Overlapping AWT lines and Swing JLabels

末鹿安然 提交于 2019-12-02 04:37:45
I have a problem in my application using line primitives and JLables . I try to explain it: I have to draw a vehicle route using lines to represent roads and JLabels to represent cities. I need the use of JLabels because each JLabel has a Listener that shows a dialog with information about the city. I redefine paint() method of my main JPanel . In that method I first in invoke the super.paint() , then I draw the lines and finally I add the Labels to the JPanel . The problem is that the lines overlap the labels regardless the matter the order of painting them. Is there any suggestion? You can

tab space on a JLabel not showing - weird - Java

可紊 提交于 2019-12-02 03:39:45
问题 I'm trying to update a JLabel with new text and I need this text to have tabed space. This is my code: public void setNewLabelTxt(String text) { nameLabel.setText(text + "\t"); } The label is updated but there is no tab space at the end and I can't figure why. As far as I know \t is the way to add tab space. 回答1: JLabel doesn't render \t in any special way (ie, it doesn't convert the \t to spaces before rendering it). Instead, you should use something like text = text.replaceAll("\t", " ");