jlabel

How to center the text in a JLabel?

守給你的承諾、 提交于 2019-12-02 21:52:12
despite many tries I can't get the result that I would like to see - text centered within the JLabel and the JLabel somewhat centered in the BorderLayout. I said "somewhat" because there should be also another label "status" in the bottom-right corner of the window. Here the bit of code responsible for that: setLayout(new BorderLayout()); JPanel area = new JPanel(); JLabel text = new JLabel( "<html>In early March, the city of Topeka," + " Kansas,<br>temporarily changed its name to Google..." + "<br><br>...in an attempt to capture a spot<br>" + "in Google's new broadband/fiber-optics project."

JLabel only shows if initComponents() is deleted

蓝咒 提交于 2019-12-02 20:04:31
问题 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()

proplem in updating JLabel in for loop

强颜欢笑 提交于 2019-12-02 19:56:11
问题 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

How to properly refresh image in JFrame?

假装没事ソ 提交于 2019-12-02 19:34:29
问题 This is a problem that disturbs me for few hours now and I'm not able to find a solution by myself... I've found similar topics all around the net, but I couldn't find exact same problem with well explained and as simple as possible solution. I've also looked at EDT and SwingWorker API docs, but it was far too complicated for me :( So, let's get to the point. I have a simple JFrame with JLabel inside, that consist of my image: private static class MyJLabel extends JLabel { private ImageIcon

When I trigger my fireball creating, it resets my Character JLabel

懵懂的女人 提交于 2019-12-02 19:08:14
问题 package clickrpg2; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.*; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.Timer; public class MainFrame extends javax.swing.JFrame implements ActionListener { static MainFrame mainFrame = new MainFrame(); static Hero hero = new Hero(); static JLabel fireballButton[] = new JLabel[1000000]; static int fireballTotal = 0; Timer timer = new Timer(10, this); public MainFrame() { addKeyListener(new

JLabel and JTextField setText is not update

我的梦境 提交于 2019-12-02 18:09:37
问题 I want to update jlabel and jtextfield with setText() method but it is not working. However, rest of the code is working. The code is below; btnDosyaSe.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int kullaniciSecimi = jfc.showOpenDialog(null); if (kullaniciSecimi == JFileChooser.APPROVE_OPTION) { File fileName = jfc.getSelectedFile(); textField.setText

How to change a cell icon of JList in run time

亡梦爱人 提交于 2019-12-02 15:37:33
问题 How can I change a JLabel icon of only one JList cell(for example: clicking in JList)? I tried to access the JLabel getting with listCellRender but it don't works: @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { ListCellRenderer r = list.getCellRenderer(); JLabel comp = (JLabel) r.getListCellRendererComponent(list, list.getSelectedValue(), list.getSelectedIndex(), false, false); comp.setIcon(UIManager.getIcon("Tree.leafIcon")); } Can anyone give some

Adding jlabel to a jframe using components

时光怂恿深爱的人放手 提交于 2019-12-02 14:51:29
I have 2 classes, My main class creates a frame and I want another class to add content to it. A bit of reading arroudn told me I should use components to do this however when I run my code the frame is empty. public static void main(String[] args) { // create frame JFrame frame = new JFrame(); final int FRAME_WIDTH = 800; final int FRAME_HEIGHT = 600; // set frame attributes frame.setSize(FRAME_WIDTH, FRAME_HEIGHT); frame.setTitle("My Frame"); frame.setVisible(true); Component1 Com = new Component1(); Component add = frame.add(Com); } My Component class creates a JLabel public class

Add a picture to a JFrame

孤者浪人 提交于 2019-12-02 13:45:07
All I am trying to do is add a picture to a JFrame . I am really confused and don't really understand... I have looked up every possible question on this site, looked on other java stuff, such as forums. I tried my best and now I must ask guys for help. I hope the code is clean and easy to read. Thanks for the help. package zeus; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.ImageIcon; public class Main extends JFrame{ public static final int WIDTH = 800; public static final int HEIGHT = 600; public static final int SCALE = 1; public static void Launch(){ JFrame xF =

background image hidding the other components like buttons labels and other, and vicce versa

故事扮演 提交于 2019-12-02 13:26:43
how to solve hidding of components in this code code is running without errors but background image not displayed how to change code to get the background image when using validation method, its creating error in validation() public class TEST{ public TEST() { String[] strm = {"Jan", "Feb", "Mar", "Apr", "May"}; String[] stry = {"2016", "2017", "2018","2019"}; String[] strf={"NEW Delhi", "Bangalore", "Chennai"}; String[] strt={"Goa","Kashmir","Hyderabad"}; JFrame f = new JFrame("test"); f.setSize(500, 500); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel lfr = new JLabel("FROM");