Hello Everyone, I am experiencing errors when trying to compile a project in Java 8. The errors are caused by swing components. The code I am using is the following: import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class Main2 { public Main2(){ JFrame f = new JFrame (); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(100, 100); JPanel p = new JPanel(); JLabel l = new JLabel("Test"); p.add(l); f.add(p); f.setVisible(true); } public static void main(String[] args) { new Main2(); } } The problems are caused by the p.add(l) and the f.add(p). They throw a `The method add(JLabel) is undefined for the type JPanel` and a `The …

Member Avatar
Member Avatar
+0 forum 3

import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JComboBox; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; public class OtakuHigh extends JFrame{ private JLabel label, label1, label2, label3, label4, label5, label6, label7, label8; private JTextField text1, text2, text4, text5, text7, text8; private JComboBox Mbox, Dbox, Sbox, Ybox, SCbox; private JButton Qbutton; String[] Month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; String[] Day = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}; String[] …

Member Avatar
Member Avatar
+0 forum 2

Using NetBeans 7.3.1 i have created a JFrame. A JLabel fills the bottom of the JFrame . The JLabel displays an ImageIcon. I want the ImageIcon automatically resize itself when JLabel resizes. Generated Code from IDE : jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Number_theory/resources/primes_ulam_spiral.gif"))); // NOI18N jLabel1.setDoubleBuffered(true); jLabel1.setOpaque(true); jLabel1.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { jLabel1ComponentResized(evt); } }); My way to change Icon's dimensions according to label's dimensions. private void jLabel1ComponentResized(java.awt.event.ComponentEvent evt) { int labelwidth = jLabel1.getWidth(); int labelheight = jLabel1.getHeight(); ImageIcon Icon = new javax.swing.ImageIcon(getClass().getResource("/Number_theory/resources/primes_ulam_spiral.gif")); Image img = Icon.getImage(); jLabel1.setIcon( new ImageIcon(img.getScaledInstance(labelwidth,labelheight ,Image.SCALE_FAST))); } The result is a slow adjustment to frame …

Member Avatar
Member Avatar
+0 forum 1

Hey Guys, I'm want to output a calculation to a JLabel. Example: double num1 = 14; double num2 = 3; double ans; ans = num1/num2; JLabel jl = new JLabel(); add(jl); jl.setText("The Answer is: " + ans); Currently the answer for this will be 4.666666667. Now if this was a System.out statement I could have just done: `System.out.printf("The answer is: %.2f", ans);`. However, I can't. So what can I do to make the number diplayed in the JLabel look like 4.66. Thank-you

Member Avatar
Member Avatar
+0 forum 3

Jython is a version of Python that can use the extensive Java library. Jython uses Python syntax and avoids the rather ugly syntax (at least for Pythonions) of Java. Here we apply it to bring up an image from a file.

Member Avatar
+4 forum 0

Hi folks, I have been making a marquee scroller that reads the text coming from the right to the left, so setting a JLabel's text using setText() starting with 60 spaces and one character-long substring, to zero spaces and 60 character-long substring. I've noticed that immediately, the jlabel's text starts to 'grow'. The first character of the text is moving to the left one character at a time, but the right hand side is (slower than 1 character at a time) moving to the right. This stops when the start of the text hits the left border of the JLabel …

Member Avatar
Member Avatar
+0 forum 2

Am trying to draw image on jpanel or jlabel when button is been click on, so i added actionperformed on my button as follows. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Image imag = new ImageIcon(this.getClass().getResource("img/top_bg.jpg")).getImage(); showPix1.setLayout(new BorderLayout()); showPix1.add(new paintPhotos(imag,20,20), BorderLayout.CENTER); } I have a separate class called paintPhotos that extends jLabel as follows package myApp; import java.awt.*; import javax.swing.*; public class paintPhotos extends javax.swing.JLabel { public Image img; int w; int h; public paintPhotos(Image img, int w, int h) { this.img = img; this.w = w; this.h = h; System.out.println("am paintclass"); } @Override public …

Member Avatar
Member Avatar
+0 forum 7

I have a JLabel and a JPanel which both implements MouseClicked methods and I have added the JLabel to the JPanel but when the JLabel is clicked, the MouseClicked method of JPanel is invoked. How to fix this>??

Member Avatar
Member Avatar
+0 forum 1

I am cresting a digital clock and I am having troubles updating the interface please can someone help me with this. I have the code below: ********/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Interface; /** * * @author Adetola-Ralph */ import java.awt.event.ActionEvent; //import javax.swing.event.*; public class Main extends javax.swing.JFrame { /** * Creates new form Main */ public Main() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this …

Member Avatar
Member Avatar
+0 forum 2

Hey guys, I've drawn a grid, and I have a label contatining a picture. Whenever I change the location of this label, the grid dissapears until I resize/move the frame. Any suggestions on best method to buffer these grid lines? They aren't going to be moving graphics or anything like that so I'm hoping for the most easiest method. pseudocode > draw x line > draw y line >set bounds of label to x,y Any ideas appeciated.

Member Avatar
Member Avatar
+0 forum 2

I am facing a strange problem, and seriously I spend lot of time in experimenting different things to get it work but all in vain. I have a JTree whose nodes are been modified by my custom TreeCellRenderer class. My class creates a JPanel for every node and places components over that panel and assign various values to them and then the node is created. I have a JLabel on it whose purpose is to display avatar of users fetched from the google talk server. Now the problem is that, the avatar icons get displayed on the jlabel when I …

Member Avatar
Member Avatar
+0 forum 1

How would I get a box to appear when I hover over a JLabel? The box is to explain what the label is. This is just a minor detail for the user-interface functionality of a game. So when a user hovers over a label, a box appears explaining it.

Member Avatar
Member Avatar
+0 forum 2

Hi, I have a jFrame with a couple of jLabels, designed in Netbeans so most of the code is generated. If I want to change the text of the label, I use .setText() inside my jFrame and it works great. Now here's the problem. If I just make a String in a new class, I want this to appear on my jLabel. I have the following code snippets: GUI.java (jFrame): [CODE]public void setjLabel_answer(String jLabeltext) { jLabel_answer.setText(jLabeltext); System.out.println(jLabeltext); }[/CODE] Spel.java: [CODE]GUI window = new GUI(); window.setjLabel_answer("hello world");[/CODE] So I get the output "test" thanks to system.out.println, but the label doesn't change …

Member Avatar
Member Avatar
+0 forum 4

Dear all I am making a program which adds lots of jlabels to a frame (the idea, eventually, is that each jlabel will link to a different program on my dekstop) The trimmed down code below shows that I have a script which creates an array of multiple jlabels which are appended to the jframe (I eventually got this working). I am now a little stuck and I would really like to know how to add the same method to each jlabel so that, when clicked, a pop up label tells me its position in the array. (e.g. the 7th …

Member Avatar
Member Avatar
+0 forum 7

Hi. I am trying to display a JFrame containing a JLabel with an image, and I can't get the image to display. The text appears fine. I've done this before with no problem, so I have no idea what is wrong. I've tried everything I can think of to fix it. [CODE]import java.awt.Dimension; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class Main { public static void main( String[] args ) { JFrame frame = new JFrame( "VN" ); JLabel image = new JLabel( "hello", new ImageIcon( "vn1.bmp" ), JLabel.LEFT ); image.setPreferredSize( new Dimension( 720, 460 ) ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); …

Member Avatar
Member Avatar
+0 forum 5

Hey here's my code for functioning like MS Paint. But JLabels are just not visible. Please Help. [CODE] import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.awt.image.*; public class MSPaint { JFrame frame; JPanel panel; Painting paint = new Painting(); public MSPaint() { frame = new JFrame("MS Paint"); frame.setSize(1024,768); panel = new JPanel(); frame.getContentPane().add(panel); panel.setLayout(new BorderLayout()); panel.add(paint); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setVisible(true); paint.getComponent(0).requestFocus(); } public void init() { } public static void main(String[] args) { MSPaint msp = new MSPaint(); } } class Painting extends JPanel implements MouseListener, ActionListener, MouseMotionListener { Raster r; int x1, y1, x2, y2; boolean point = true, circle, line, …

Member Avatar
Member Avatar
+0 forum 2

I want to be able to create JLabels, all different names, with a for loop ex: [CODE] static JLabel[] totalAYearLabelYr = new JLabel[termYears]; [/CODE] So I got 30 JLabels named totalAYearLabelYr, which I'm not sure you can have 30 JLabels named the same thing. I wanna name them all totalAYearLabelYr1 totalAYearLabelYr2 totalAYearLabelYr3 totalAYearLabelYr4........as much as the termYears is, etc. I wanna then setBounds to each Label [CODE] for (int i = 0; i < mc.getTermYears(); i++) for (int v = 295; v <= 1; v += 25) totalAYearLabelYr[i].setBounds(10, v, 375, 20); [/CODE] Then add it to the pane (I'm not …

Member Avatar
Member Avatar
+0 forum 13

I want to load an image for each different shoe and I'm using JLabel to help me do this. I put the image's path in the JLabel constructor but when the code runs, it doesn't display any image. Instead of an image, the image path is written. appreciate any help and suggestion [CODE]package badmintonstore; /** * * @author TaimooR */ import java.awt.GridLayout; import javax.swing.*; /* * The class displays shoes */ public class Shoes extends JPanel { //Class Fields private JLabel icon; private JLabel price; private JTextField qtyInput; private double priceS = 0.0; public Shoes (String showPrice,String path) { setLayout(new …

Member Avatar
Member Avatar
+0 forum 4

I'm having some fundamental issues with some basic abstraction. Here is the super class: [CODE] public abstract class Tile extends JLabel implements MouseListener { public Tile() { setIcon(new ImageIcon(getClass().getResource("images/blank.gif"))); } @Override public void mousePressed(MouseEvent e) { System.out.println("clicked"); switch(e.getModifiers()) { case InputEvent.BUTTON1_MASK: leftClick(); break; case InputEvent.BUTTON2_MASK: rightClick(); break; } } public abstract void leftClick(); public abstract void rightClick(); } [/CODE] sub class: [CODE]public class Mine extends Tile { @Override public void leftClick() { System.out.println("left clicked"); } @Override public void rightClick() { System.out.println("right clicked"); } }[/CODE] When I implement this on a JFrame, the image is visible, but the MouseListener is not …

Member Avatar
Member Avatar
+0 forum 1

Hi guys, I'm trying to create a 2D array of JLabels my first problem is actually creating them. my code atm is = [CODE] package test; import java.io.File; import javax.swing.JLabel; import javax.swing.JPanel; public class testing extends javax.swing.JFrame { /** Creates new form testing */ public testing() { initComponents(); for(int i = 0; i < 10; i++) { for(int j = 0; j < 10; j++) { jPanel1.add(new javax.swing.JLabel("I:" + i + " J:" + j)); } } this.repaint(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. …

Member Avatar
Member Avatar
+0 forum 6

public class OpenMenuListener implements ActionListener { public void actionPerformed(ActionEvent ev) { if(ev.getSource() == a) { f2 = new JFrame("shashikant verma"); p2 = new JPanel(); f2.getContentPane().add(p2); String str = "<html>"+"<h>"+"<P ALIGN = \"CENTER\">"+"<i>"+"<font size = \"10\">"+"<font color= \"#800080\">"+"CORRECT DEFINITION AND<br>"+"STRUCTURE OF FUNCTION y = f(x) "+"<br>"+"</i>"+"</h>"+"<P ALIGN = \"LEFT\">"+"<font size = \"6\">"+"<u>"+"Introduction <br>"+"</u>"+"<P ALIGN=\"LEFT\">"+ "<font size = \"4\">"+ "It is a well-known fact that the Logicians,Mathematicians and Physicists have been pointing out about deficiencies in the definition<br>"+ "and structure of a function.This will lead us to the conclusion that in many physical phenomena there are failure processes <br>" + "of Physics …

Member Avatar
Member Avatar
+0 forum 4

The End.