jlabel

Some Swing Components not showing on JFrame

為{幸葍}努か 提交于 2019-12-25 07:25:58
问题 I've got a serious problem. When I try to add 2 JRadioButtons and a JLabel on my JFrame, it doesn't work. They are not showing, but other elements do. The funny thing is, that other components which I added before (also JLabels) are visible on the JFrame. All swing components are added over a container 'panel' which is the content pane of the JFrame. I'm using Java DK 7 u67. Here's the code: (Scroll down to /*This code doesn't work */ ) public class UDP_FileTransfer implements KeyListener,

Getting error: variable private acces in Component

允我心安 提交于 2019-12-25 06:28:23
问题 I'm stuck at this error, 'name has a private access in Component'. I don't understand what it means, but I think I may have wrongly initialized the variable 'name' in the main method. The error points inside the startGame() method, where I initialized 'label1'. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Gamey extends JFrame { private JPanel panelUp; private JPanel panelDown; private JButton btnPlay, btnNext; private JLabel label1; public Gamey() { super(

updating jlabel

非 Y 不嫁゛ 提交于 2019-12-25 05:14:44
问题 I am having trouble updating a jlabel in a method. here is my code: JLabel curStatus = new JLabel(""); JButton jbtnSubmit; public static void main(String[] args) { test gui = new test(); gui.startGUI(); // gui.setCurStatus("testing!"); << seems to work here, //but when i call it from another class, it doesn't want to run. } // Set up the GUI end for the user public void startGUI() { // These are all essential GUI pieces new JTextArea(""); final JFrame jfrm = new JFrame("my program"); jfrm

fixing JScrollPane with JLabel

时间秒杀一切 提交于 2019-12-25 04:25:04
问题 In order to add a background Image , I work on JLabels instead of JPanel . JFrame frame=new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label=new JLabel(new ImageIcon("bg.png")); label.setLayout(new BoxLayout(label, BoxLayout.Y_AXIS)); for(int i=0;i<20;i++) label.add(new JLabel(i.toString())); frame.add(label); the problem here is that only components that fit the background image will be shown (in my example only the 10 first JLabels) I tried using a JScrollPane

Can I change the text of a label from a Thread in Java?

纵饮孤独 提交于 2019-12-25 03:19:18
问题 I have another question for this forum. I am writing a small application with Java in which I have multiple Threads. I have two Threads that are in two different classes. I have one Thread ( thread1 ) dedicated to defining all of the JFrame components. (JPanels, JButtons, ActionListeners, etc.) In another Thread, ( thread2 ) I am checking for a variable ( v ) to equal a certain value. ( 98 ) When this variables does change to equal 98 , that same thread is supposed to update a JLabel. (Let's

How to Position a JLabel in the specified Layout?

百般思念 提交于 2019-12-25 03:18:19
问题 I am trying to position my Labels and Button on screen. I found an answer here to set label's Position using: label3.setHorizontalAlignment(SwingConstants.CENTER); label3.setVerticalAlignment(SwingConstants.CENTER); but there has been no effect in my code. Also, on changing my layout from Flow Layout to Border Layout, only one Jbutton [CLEAR] appears on the Screen. Can anyone help me rectify this? public class Corrected1 extends JFrame { public JTextField tf1; public JTextField tf2; public

JLabel disappears after scrolling

柔情痞子 提交于 2019-12-25 02:59:20
问题 I've got scroll panel which contains ImageIcon . I want to add JLabel with absolute position in px. What I've got: The code: public class HelloWorld { HelloWorld() { JFrame jfrm = new JFrame("Hello, World!"); jfrm.setSize(640, 480); JPanel mapPanel = new JPanel(); mapPanel.setLayout(null); mapPanel.setSize(600,400); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ImageIcon imageIcon = new ImageIcon("src\\SwingExp\\img\\map.gif"); JScrollPane scrollPane = new JScrollPane(new JLabel

JLabel disappears after scrolling

浪尽此生 提交于 2019-12-25 02:59:13
问题 I've got scroll panel which contains ImageIcon . I want to add JLabel with absolute position in px. What I've got: The code: public class HelloWorld { HelloWorld() { JFrame jfrm = new JFrame("Hello, World!"); jfrm.setSize(640, 480); JPanel mapPanel = new JPanel(); mapPanel.setLayout(null); mapPanel.setSize(600,400); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ImageIcon imageIcon = new ImageIcon("src\\SwingExp\\img\\map.gif"); JScrollPane scrollPane = new JScrollPane(new JLabel

How to make jLabels stay attached to the corners of a window form, despite resizing the form in java?

送分小仙女□ 提交于 2019-12-25 02:43:38
问题 I have 4 jLabels in my java program, which i placed in 4 corners I want them to stay there despite user resizing the window. I have written the code for the labels, but cannot seem to figure out how to keep them glued to each corner. here is my code for the jLabels JLabel label_1 = new JLabel(""); label_1.setEnabled(false); label_1.setBounds(0, 0, 19, 19); contentPane.add(label_1); JLabel label_2 = new JLabel(""); label_2.setEnabled(false); label_2.setBounds(0, 242, 19, 19); contentPane.add

How Do I Put JLabel and JTextField on top of Image?

六月ゝ 毕业季﹏ 提交于 2019-12-25 02:24:11
问题 I am trying to create a game where I have a background image and text on top of that in the form of JLabel s. How would I go about doing that? The main reason I'm doing this is so that I can have 2 different text areas with different font sizes. Using g.drawString() will only let you use 1 text size for the whole thing. Here is my code so far: package com.cgp.buildtown; import java.awt.Font; import java.awt.FontFormatException; import java.awt.Graphics; import java.awt.Graphics2D; import java