Results 1 to 2 of 2
- 03-18-2012, 09:43 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 24
- Rep Power
- 0
jlabels don't size by using setbounds within a null layout
Hi, i am quite new to java.
i can't set a jlabels size while using a null layout. afaik, everything else is working just fine... problem is that setbounds won't change the jlabel's size. i have tried everything i can think of, but, nothing is working.
import java.awt.Color;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class crash extends JFrame {
{
JFrame frame = new JFrame("test");
frame.setBounds(0, 0, 1920, 1080);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setLayout(null);
frame.pack();
frame.setVisible(true);
{
JPanel panel = new JPanel(null);
panel.setBackground(Color.black);
panel.setLayout(null);
panel.setBounds(0, 0, 1000, 800);
frame.add(panel);
panel.setVisible(true);
{
setLayout(null);
JLabel jl = new JLabel("test text");
jl.setFont(new Font("Arial", Font.PLAIN, 20));
jl.setBounds(200, 200, 400, 400);
jl.setForeground(Color.blue);
panel.add(jl);
jl.setVisible(true);
}
}
}
}
- 03-18-2012, 12:00 PM #2
Re: jlabels don't size by using setbounds within a null layout
1) Look around the FAQs section of the site and learn how to post code so it retains its formatting.
2) Don't use a null layout and setBounds(...), use an appropriate layout manager: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
3) Follow coding conventions. Class names start with an uppercase letter.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Swing JApplet, what is the right layout for free located canvas + jlabels ?
By jaho in forum AWT / SwingReplies: 5Last Post: 02-28-2012, 01:49 PM -
Size of serialized object with null values
By jamesd128 in forum New To JavaReplies: 1Last Post: 10-22-2010, 06:43 PM -
add scrollbar in JFrame with null Layout
By sajib_bd in forum AWT / SwingReplies: 1Last Post: 10-12-2010, 09:53 AM -
group layout - link the size of components in different labels ?
By random7 in forum AWT / SwingReplies: 4Last Post: 08-05-2010, 08:08 AM -
set button size in case of layout managers
By silversurfer2in in forum AWT / SwingReplies: 3Last Post: 06-22-2010, 10:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks