Swing/AWT/SWT :: JLabel Does Not Display
May 8, 2014
I'm having problems getting my program to display a JLabel. The program draws shapes of random size and color across a panel. I have this part working. (There is more code for the drawing of shapes, I left it out for easier reading). When I try to add a JLabel in the main method, it does not display.
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestDraw {
[Code] .....
View Replies
ADVERTISEMENT
Mar 27, 2015
i have very critical problem in my collage project i have try many code but still i cant solve this problem, i want to display image on jlabel or jpanel with respect of components size without use of drawimage method
View Replies
View Related
Sep 30, 2014
The problem I'm trying to resolve now is getting my ActionEvent to send the value input in the JTextArea out to be calculated, then to display the result in my result JLabel.
Here is an image of the GUI :
The basic procedure the teacher is asking for is the user is supposed to enter a temperature in the input. The user then clicks the input scale, and then on the output scale selection the converted value is to be displayed in the output area.
As I mentioned my problem is in the sending of the input value to my calculation area, and getting the value to display in the JLabel.
How should I approach this solution? Do I need to have a listener after the JTextArea of the input box? Will that allow me to limit the input values to numbers only?
final JTextArea inputText = new JTextArea("" + (char)176,1,4);
//ReadConsole equivalent to specific input was a number?
Here is the section of code my ActionListener is:
//celOut represents the Celcius output scale JRadioButton.
celOut.addActionListener (new ActionListener () {
@Override
public void actionPerformed(ActionEvent e) {
//if the Celcius Input Scale is selected.
if(cel.isSelected())
[Code] ....
All the calculations are required to occur in a separate java file, which what I think is tripping me up. How do I send a value from the JTextArea into the Calc.celToFahr method?
//contents of my Calc.java calculation class.
public class Calc {
public static double celToFahr(double cel){
return cel * (9./5.) + 32.;
}
public static double fahrToCel(double fahr){
return (fahr - 32.)*(5./9.);
}
}
View Replies
View Related
Jul 21, 2014
I have written a code to rotate a Jlabel but i am facing some problems.
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import javax.imageio.ImageIO;
[Code] ....
View Replies
View Related
May 6, 2014
How can I access to a jLabel of a class from another class or edit its text?
View Replies
View Related
Feb 27, 2014
I'm trying to make a JLabel with an image fade in from transparent to fully visible.Is this possible with the JLabel itself or would I have to change the Image? If I'd have to change the Image's opacity how would I do this?
View Replies
View Related
Apr 24, 2014
I am trying to write an application where if you click and hold down on 1 button and move the mouse to another button and release the text on the 2 buttons should be switched around.I have a print line so I can se the text are supposed to get switched around but it is just not happening in the GUI.
I attached all my code in case the flaw was to find somewhere else in the code, but the functionality I am working on is the lines 76 to 121.
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
[code]....
View Replies
View Related
May 26, 2014
Create a dnd (dungeons and dragons) character creator and back ground generator, have it display and run on a gui, to start with i decided to creator the gui as i go so i can see the progress, first i tried eclipse and windows builder, well after 1 day of reinstalling windows builder in about 5 different ways from multiple guides and sometimes getting it to partly work ...
After doing some more research I have figured out how to get the main program to display the gui . Heres what i have:
package com.mrgreaper;
import javax.swing.*;
public class MainWindow {
private JPanel mainWindow;
private JLabel playerlbl;
private JLabel playerNamelbl;
[Code] .....
Now this works fine and the gui displays when the program is run but I can't change the text of any of the jlabels or textfield. If I try to do it in the main class i need to change them from private to public static but then in the form builder it says "cannot bind to static field *name of field*" but if i take static off then i cant change its value!
From what i understand this is because the window is an instance, so how to i change the value in that instance? I could put all my code in the one class, the one that creates the gui, but i really want it seperate, i would like the gui to update as the code runs... So how do i do it, how do i change the contents of jlabels on the fly, read the contents of text boxes on the fly etc....
I tried adding a getter setter
public void setCharFirst(JLabel charFirst) {
this.charFirst = charFirst;
}
in the MainWindow.class
Then i tried to set it from my main function
MainWindow.setCharFirst("test");
but it cant access it as my main function is static and it is not now can i make it static...
View Replies
View Related
Nov 18, 2014
why JLabel setText method is not setting up the text dynamically even though i am calling repaint() once i set the text? Code snippet is below
Locale currentLocale = new Locale(panel.getCountryLocal(), panel.getCountry());
ResourceBundle messages = ResourceBundle.getBundle(Constants.messageBundle, currentLocale);
messages = Panel.getMessages();
String displayString = messages.getString("101022");
[code]....
View Replies
View Related
Jun 26, 2014
I am trying to build an app for managing expenses to practice with java programming. I am stuck on the ActionEvent block. The program i am trying to make needs to minus the expenses from the monthly income and display the net income in JLabel.
package mybudgetapp;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
[Code] .....
View Replies
View Related
Nov 11, 2014
I want to create 3 JTextFields in a row with all being of equal size.But my first Text field gets so wide than the other two.After adding each component at a time and seeing what causes the problem I realized that if I type a long text for the JLabel that's when this problem occurs.If I reduce the length of the text in the JLabel JTextFields get into the sizes I want. Here's my code
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class Calculator1 extends JFrame {
JTextField value1=new JTextField("0");
JTextField value2=new JTextField("0");
[Code] ....
How can I stop the JTextFields changing size when I change the JLabel label1's text length...
View Replies
View Related
Sep 14, 2014
I am working on a project (assignment) and i want to be able to click on jlabel and the select border will show (as shown in the image attached) and i used it to resize the jlabel. I tried
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
setPreferredSize(getSize());
}
});`
yet is not working. I tried some other code that are not working.
View Replies
View Related
Sep 20, 2014
I don't get what I missed in the code. I used the example of changing the text of a button by clicking on it, but instead I also added a JLabel and tried to make the button change its text instead, but it didn't work. What did I do wrong?
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class Buttone implements ActionListener{
JLabel label;
JButton button;
[Code] ....
View Replies
View Related
Jul 30, 2014
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){
if (e.getSource ==add) {
if (text.getText().equalsIgnoreCase("Exam Schedule")){
link1.setText(text.getText());
link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
[Code] .....
View Replies
View Related
Feb 20, 2014
I'm trying to create a chess program in java swing, and for the board I'm using an 8 by 8 array of jlabels stuck inside a jpanel with a grid layout. I would like the board to change size when the window changes size, and the grid layout accomplishes this succesfully, until I add the actual icons to the jlabels. Then the board just stays a fixed size. Someone suggested I use their "Stretch Icon" class, found here:[URL] ...., so I tried initializing the icons using one of the constructors in the class (the one that takes an image name and a boolean value for whether or not you want the resisizing to be proportionate (to maintain the aspect ratio)). However, the same thing happened. The board appears, but it does not resisize. To attempt to fix this problem, I tried simplifying my code, reducing the program to two jlabels within the jpanel, for which I then tried to set the image in the same way. Here is my simplified code:
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
[Code] ....
I'm misusing the stretch icon class, or just generally what's going wrong/how to fix it?
View Replies
View Related
Feb 2, 2015
i want to have a JLabel that could "robotically" type words character by character.
View Replies
View Related
Mar 27, 2014
The code below is just the GUI for a slot machine. Currently when play is clicked it displays the random number, I'm trying to make it so each random number displays an image in the GUI instead. For example if the random numbers were 2,2,3 it would display Cherry, Cherry, Bells. I started changing field1 to the image but realised I was on the wrong track as it would just display the same image not one allocated to a number. I've left in what I started doing.
how to do it?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SlotMachineGUI {
JPanel mainPanel;
SlotMachine slotEngine;
[code]....
View Replies
View Related
Feb 15, 2015
I have the code here to populate a GUI. I have the math and then print out and return a single number. I have tried to use setText in the class CalculateButtonHandler.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RectangleProgram extends JFrame {
private JLabel lengthL, widthL, areaL, perimeterL, averageL;
[Code] ....
View Replies
View Related
Mar 28, 2015
why this code, doesn't display the image?
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
[code]...
View Replies
View Related
Sep 25, 2014
I am in the middle of creating a chess application, and am currently working on laying out a list of moves on the right of the actual board. Specifically, I want to have a JLabel that says "moves" on top of a JList that contains the moves, on top of two buttons, labeled "<" and ">" respectively, to which I will eventually add functionality to take back and un-take back moves. Currently I have the first two parts down, but when I add my buttons,the other components are getting messed up.
I have all of these things in a vertical BoxLayout inside of a JPanel with a fixed width of 70, and a height that varies according to the size of the window (I overrode the getPreferredSize method of the JPanel). The two buttons are within their own JPanel with a grid layout with one row and two columns. Then I basically just add the moves list label, the movesList, and the panel housing the buttons to the larger panel, in that order.
However, I am encountering two problems. One, the buttons display the text "... " instead of "<" and ">" as if there is not enough room, although I'm pretty sure three periods take up more space than one less than or more than sign. The next is that, without the buttons at the bottom, the label reading "moves" is appropriately centered (or left aligned, I can't tell which) over the movesList, and you can read its whole text. However, when I add in the buttons at the bottom, the label of the top shifts over to the right and then reads "mov..." because it has run out of room.
Here is my code:
//move list
movesListLabel = new JLabel("Moves");
//the components for the actual movesList come from another class with an object called pen, but I don't think this is the problem
listModel = pen.getListModel();
JList movesList = pen.getMovesList();
JScrollPane listScroller = pen.getMovesListScrollPane();
[Code] .....
View Replies
View Related
Jan 19, 2014
I have a class that retrieves an image, and a class that is a game. I want to put my image onto the game to use it as the main figure. As of right now in eclipse, the game class runs, so the game works, but the image doesn't do anything. Need to put the image into the game? Here is my image class:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
[code]....
View Replies
View Related
Jan 16, 2014
How to display an image on a JFrame. If you can, pany example code.
View Replies
View Related
Oct 28, 2014
I'm doing a project in which I must display prices of computer accessories in a Scroll Pane viewer. The if statements are all checkboxes. I am completely lost with how to print to the viewer if a checkbox is selected. Furthermore, I am also lost with how to add up all of the checkboxes.
private void USBCheckActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double area = 0;
double computerprice = 500.0;
if (printerCheck.isSelected()){
double printer = 100.0;
[Code]...
View Replies
View Related
Aug 8, 2014
I am fairly new to Java. I am trying to learn some image manipulation basics. I have searched the web endlessly and made numerous attempts but I cannot seem to get a darn image to display. This code is my latest attempt in Eclipse. The file I am using is chairangle.jpg which is is the src folder of the package I am working in in Eclipse. I am on Windows 8.
import java.awt.*;
import javax.swing.*;
import javax.swing.ImageIcon;
public class otherimg extends JFrame
{
public static void main(String args[]){
JFrame f = new JFrame();
ImageIcon image = new ImageIcon("image/chairangle.jpg");
JLabel label = new JLabel("", image, JLabel.CENTER);
JPanel panel = new JPanel(new BorderLayout());
panel.add( label, BorderLayout.CENTER );
f.pack();
f.setVisible(true);
}
}
View Replies
View Related
Oct 5, 2009
i need to display the data from an xml file in a DefaultTableModel using the addRow method. in my table there are three columns named "symbol", "info" and "value", so i must create arrays of string objects from nodelists and insert them in the model with something like - addRow(new Object[] { getSymbolData, getInfoData, getValueData } ); but im stuck and cant seem to get it right.
View Replies
View Related
Sep 26, 2014
I have this panel in a nested class in the MainPanel class and it does not display, when I launch the applet, or more like, the two menus "LineColor" and "BackColor" from the nested class ColorPanel do not display .
This is the code:
package ui.panels;
import interfaces.Resettable;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Panel;
[code].....
View Replies
View Related