473,761 Members | 10,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding a JLabel to a JFrame

Shinzon
7 New Member
ok so far I have got:

Expand|Select|Wrap|Line Numbers
  1. JFrame frame = new JFrame( "Matt's DVD's" );
  2.        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  3.        frame.setSize( 420, 170 ); // set frame size
  4.        frame.setVisible( true ); // display frame
  5.        JLabel label = new JLabel("Text Label");
  6.  
I want the jlabel to go inside of the jframe but cant seem to figure out how to do that so I was wondering if anyone could help me.
Jul 10 '07 #1
5 6856
JosAH
11,448 Recognized Expert MVP
ok so far I have got:

Expand|Select|Wrap|Line Numbers
  1. JFrame frame = new JFrame( "Matt's DVD's" );
  2.        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  3.        frame.setSize( 420, 170 ); // set frame size
  4.        frame.setVisible( true ); // display frame
  5.        JLabel label = new JLabel("Text Label");
  6.  
I want the jlabel to go inside of the jframe but cant seem to figure out how to do that so I was wondering if anyone could help me.
JFrames have a content pane (it's an ordinary Component). Add your label to
that content pane (don't forget to set an appropriate LayoutManager to that
pane first if the default one (BorderLayout if I'm not mistaken) first).

kind regards,

Jos
Jul 10 '07 #2
r035198x
13,262 MVP
ok so far I have got:

Expand|Select|Wrap|Line Numbers
  1. JFrame frame = new JFrame( "Matt's DVD's" );
  2.        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  3.        frame.setSize( 420, 170 ); // set frame size
  4.        frame.setVisible( true ); // display frame
  5.        JLabel label = new JLabel("Text Label");
  6.  
I want the jlabel to go inside of the jframe but cant seem to figure out how to do that so I was wondering if anyone could help me.
Ha ha.
Oh and don't forget to setVisible to true after adding the label.
Jul 10 '07 #3
Shinzon
7 New Member
How exactly would I go about doing that? maybe a quick snippit of code to show me or perhaps a website that has a detailed showing because I am very new to java and cannot seem to make it work.
Jul 10 '07 #4
r035198x
13,262 MVP
How exactly would I go about doing that? maybe a quick snippit of code to show me or perhaps a website that has a detailed showing because I am very new to java and cannot seem to make it work.
There's a tutorial about frames here.
But you'll want to read about layout managers too.
Jul 10 '07 #5
JosAH
11,448 Recognized Expert MVP
How exactly would I go about doing that? maybe a quick snippit of code to show me or perhaps a website that has a detailed showing because I am very new to java and cannot seem to make it work.
This part of Sun's Swing Tutorial tells you exactly how to stick JLabels
in a top level container (a JFrame).

May I recommend you'd read the entire tutorial? It's fun.

kind regards,

Jos
Jul 10 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7593
by: Jean-Philippe Martin | last post by:
Hi all, It's my first post here, so you doubt I have a question :o) I want to develop a mini graphical editor. Imagine that I have 2 JFrame, I want to have one with a list of JToggleButton with a ImageIcon and one called DrawingAeraWind with nothing into. I would like to be able to draw the ImageIcon of the selected JToggleButton in the DrawingAeraWind if I click into this window. I would like to be able
1
2447
by: SDyke | last post by:
I have a java class that creates a JFrame with a JLabel. After the frame is created I would like to feed a value to to the label, say a parameter in my call command for example. I cannot figure out how to reference the label.
0
2405
by: porky008 | last post by:
I need to add a search button to this and have no clue how to do it. Can some one please help me on this? import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.JFrame.*; class Testing {
2
25596
by: reon | last post by:
Hi in this code when i clicked login button...it shows output as login... But when i clicked each time its repeating .. i want to see that only ones ... I want to clear the previous login before i clicked... import java.awt.*; import java.awt.event.*; import javax.swing.*;
5
6921
Shinzon
by: Shinzon | last post by:
Ok so I have been working on this for a moment now and wondering how to add multiple jlabels to a jframe. the code looks like this: JLabel jl = new JLabel("DVD ID #= " + dvd); //Displays DVD id JLabel j2 = new JLabel("Name of DVD = " + dvd); //Displays dvd name JFrame frame = new JFrame( "Matt's DVD's" ); // Sets frame for label frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
8
2054
nexcompac
by: nexcompac | last post by:
Ok, I am working on an inventory program and this is where I am at thus far. I seem to be getting two errors that I can not figure out. I will post the errors at the end of the code. import java.util.*; import java.awt.*; import javax.swing.*; import java.awt.event.*;
3
2364
nanhiPari
by: nanhiPari | last post by:
hello everyone i need to create DYNAMIC JLABElS(say 5)..yes i know it sounds easy but i also have to give them Events n then want to refer each of them when ever Mouse is Clicked on a Specific Label with its Label Name or Text.. i tried it by...
1
1636
by: CodeTilYaDrop | last post by:
Hello, I am trying to show a shape in the Javax.swing.JFrame package. I am using a frame to show it, but I can not get the add method to work. Can someone give me a good example of adding something to a frame with an add method. My code looks like the following: frame.add(component); I get an error message when trying to add the component to the frame. Any suggestions please....
2
1689
by: KiranJyothi | last post by:
Hi All, I am trying to add buttons and I am not able to see them while running. Please let me know where I am going wrong. Thanks in advance. KiranJyothi <CODE> //KiranJyothi
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.