473,441 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

Wrong display of JComponents (Java)

Hello,

Java: 1.6.0_23
Netbeans: 6.9.1

I`m making chatting program and I wanted to add a background image to the main window. So I added a image via JPanel and after that the components are no longer displaying properly. The components are displayed after i point/click on them with the mouse, except the JLabel components. On the attached screenshots you can see what is the problem and the difference. Here is the code of the window:

Expand|Select|Wrap|Line Numbers
  1. public Login() {
  2.         BufferedImage icon = null;
  3.         URL path = null;
  4.  
  5.         language.Init(); // The applications is multilangual, so initializes the language
  6.         this.setTitle(language.getMessage("LOGIN_WINDOW_TITLE")); 
  7.  
  8.         path = getClass().getResource("images/securChatter_01.jpg");
  9.         JPanel panel = new WindowBackground(new ImageIcon(path).getImage());
  10.  
  11.         panel.setLayout(new GridBagLayout());
  12.         GridBagConstraints gbCons = new GridBagConstraints();
  13.  
  14.         //adding the components
  15.         gbCons.gridx = 0;
  16.         gbCons.gridy = 0;
  17.         lblUserName = new JLabel(language.getMessage("USERNAME"));
  18.         panel.add(lblUserName, gbCons);
  19.  
  20.         gbCons.gridx = 0;
  21.         gbCons.gridy = 1;
  22.         txtUsrName = new JTextField(10);
  23.         panel.add(txtUsrName, gbCons);
  24.  
  25.         gbCons.gridx = 0;
  26.         gbCons.gridy = 2;
  27.         lblUserPwd = new JLabel(language.getMessage("PASSWORD"));
  28.         panel.add(lblUserPwd, gbCons);
  29.  
  30.         gbCons.gridx = 0;
  31.         gbCons.gridy = 3;
  32.         txtUsrPwd = new JPasswordField(10);
  33.         panel.add(txtUsrPwd, gbCons);
  34.  
  35.         JPanel btnPanel = new JPanel();
  36.         btnPanel.setLayout(new FlowLayout());
  37.  
  38.         icon = loadIcon(labelIcon, "loginIcon.png");
  39.  
  40.         lblLoginIcon = new JLabel(new ImageIcon(icon));
  41.         lblLoginIcon.setToolTipText(language.getMessage("LOGIN_BUTTON"));
  42.         lblLoginIcon.addMouseListener(this);
  43.         btnPanel.add(lblLoginIcon);
  44.  
  45.         icon = loadIcon(labelIcon, "registerIcon.png");
  46.  
  47.         lblRegisterIcon = new JLabel(new ImageIcon(icon));
  48.         lblRegisterIcon.setToolTipText(language.getMessage("REGISTER_BUTTON"));
  49.         lblRegisterIcon.addMouseListener(this);
  50.         btnPanel.add(lblRegisterIcon);
  51.  
  52.         icon = loadIcon(labelIcon, "settingsIcon.png");
  53.  
  54.         lblSettingsIcon = new JLabel(new ImageIcon(icon));
  55.         lblSettingsIcon.setToolTipText(language.getMessage("SETTINGS_BUTTON"));
  56.         lblSettingsIcon.addMouseListener(this);
  57.         btnPanel.add(lblSettingsIcon);
  58.  
  59.         gbCons.gridx = 0;
  60.         gbCons.gridy = 4;
  61.         gbCons.anchor = GridBagConstraints.CENTER;
  62.         gbCons.gridwidth = 2;
  63.         panel.add(btnPanel, gbCons);
  64.  
  65.         getContentPane().add(panel);
  66.         setSize(150, 180);
  67.         setLocationRelativeTo(null);
  68.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  69.         setVisible(true);
  70.     }
Here is the code of WindowBackground:

Expand|Select|Wrap|Line Numbers
  1. public class WindowBackground extends JPanel {
  2.  
  3.     // The Image to store the background image in.
  4.     Image img;
  5.  
  6.     public WindowBackground(Image img) {
  7.         this.img = img;
  8.     }
  9.  
  10.     public void paint(Graphics g) {
  11.         // Draws the img to the BackgroundPanel.
  12.         g.drawImage(img, 0, 0, null);
  13.     }
  14. }
Attached Images
File Type: jpg withBackgroundImage.jpg (8.1 KB, 101 views)
File Type: jpg withoutBackgroundImage.jpg (6.1 KB, 96 views)
Dec 28 '10 #1
0 1336

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

Similar topics

5
by: apchar | last post by:
I am trying to use php as a kind of servlet to act as a middle man between a java applet and mysql. I know java has jdbc but it's flakey and painful. php access to mysql is much nicer. So I have:...
0
by: Frlo | last post by:
Hi, I have problem that I tried to solve but i missed out. My situation: I have problem that my page www.vodotika.sk display some wrong characters. Apache server 2.0.54 runs on windows-1250...
5
by: Zach | last post by:
This is all on linux using jdk1.3. My application is written in AWT, no swing. The application requires running it on the host machine and tunneling the GUI back to a client. I've been doing...
4
by: Abram Friesen | last post by:
Hi all, I'm a newbie at DB2 and trying to create a simple java UDF. When I call my function, I'm receiving SQL4306N. Could someone please tell me what I'm doing wrong here? Here is my java...
3
by: SJM | last post by:
I have a problem that occurs occasionally with a db for a undetermined reason which I would love to solve. I construct and append a series of 7 records to a table using ADO recordset. Each record...
2
by: Paul | last post by:
Hi I have some code and java script, when the page initially loads I want it to have focus on dr_tx_names. This works. The page loads a second time with a dropdown selection and in the code...
3
by: nkechifesie | last post by:
I want my form to display the absolute position and the recordcount of the records in the database but it keeps shoing me -1 for both . Why? this is the code Private Sub MnuOVehType_Click()...
9
by: TomC | last post by:
Is there any resource where someone who is familiar with Java might find which .NET classes are similar to classes they are familiar with in Java? For example, I have a project that I'd like to...
3
by: rajarya | last post by:
Hi, I m designing a HTML page(index.html),here i have 2 frames,by defult both frames have index1.html and index2.html as their source . in first frame(index.html) ,i have some redio buttons,and a...
4
by: phpuser123 | last post by:
I just happened to read abt vectors in java..For some practice,I implemented this small script where I Store objects in a vector..Then,I want to invoke the methods of the corresponding objects.My...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.