• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Blank Frame being displayed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I write a class extending JFrame. I add text boxes to it in the constructor. Now I instantiate the class and set it visible. This works fine in Windows 2k but when I use Windows XP the frame comes up blank. On maximising and minimizing or just moving it across the screen , the text boxes are displayed. I try repaint(), validate() and setting java option to -Dsun.java2d.d3d=false, but in vain . Can anyone please help me out in this regard. Thanks

Bharath S
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post a minimal example program demonstrating your problem.
 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Bharath S",

Please review the JavaRanch naming policy and update your user name.

As Jeff mentioned - posting your code will help troubleshoot the problem.
 
Bharath Sekar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks John and Jeff.

Here's my minimal code

import java.awt.*;
import javax.swing.*;

public class LoginFrame extends JFrame implements KeyListener
{
XYLayout layout;
javax.swing.JPasswordField Password;

public LoginFrame(String args[])
{
layout = new XYLayout(369,151,0);
getContentPane().setLayout(null);
setVisible(false);
setSize(369,151);
setFont(new Font("Dialog",Font.PLAIN,12));
setBackground(new Color(12632256));
Password = new javax.swing.JPasswordField();
Password.setEchoChar("0");
Password.setBounds(100,39,208,22);
getContentPane().add(Password);
// Adding Ok and Cancel Buttons along with Key listeners
}

public void setVisible(boolean b)
{
if(b)
{
setLocation(300,300)
}
super.setVisible(b);
}

// other methods for KeyListener
}

public class MainPrg extends JFrame
{
static public void main(String args[])
{
LoginFrame login = new LoginFrame(args);
login.setVisible(true);
//login.repaint() // didnt work
//login.validate() // didn't work - only blank frame at the start
}
}

Please lemme know this code snippet helps to figure out the problem.
I would restate the problem. On running the MainPrg, at the start only a blank frame, without the password field and the buttons, appears. But on just dragging the frame around the frame appears with the password field and the buttons. This problems has cropped up only after the update to XP. While I was using windows 2000 this worked fine. Moreover it still works fine on a Windows 2000 machine. Please help me out.

Thanks
Bharath S
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't compile your code because of "XYLayout" -- it's not part of Swing and it looks nasty -- it's forcing you to put numbers into your layout code. That can't be good.
 
Bharath Sekar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Jeff.

Here's is the code snippet which can be compiled and run

/* code for XYLayout.java */

import java.lang.*;
import java.awt.*;
import java.util.Vector;

public class XYLayout implements LayoutManager
{
private int row_count;
private int col_count;
private int YShift = 0;

Vector component_list;

public XYLayout(int h, int v, int yshift)
{
row_count = h;
col_count = v;
component_list = new Vector(5,5);
}

public void addLayoutComponent(String name, Component comp)
{
}

public void removeLayoutComponent(Component comp)
{
}

public void add(int x, int y, int w, int h, Component comp)
{
if(comp==null) return;
if(x>=row_count) x=row_count-1;
if(x+w>=row_count) w=row_count-x;

if(y>=col_count) y=col_count-1;
if(y+h>=col_count) h=col_count-y;

CompParam c = new CompParam(comp,x,y,w,h);
component_list.addElement(c);
}

public Dimension preferredLayoutSize(Container parent)
{
return null;
}
public Dimension minimumLayoutSize(Container parent)
{
return null;
}
public void layoutContainer(Container parent)
{
}

class CompParam
{
public CompParam(Component c, int xx, int yy, int ww, int hh)
{
comp = c;
x = xx;
y = yy;
w = ww;
h = hh;
}
Component comp;
int x;
int y;
int w;
int h;
}
}

/* Code for LoginFrame.java */
import java.awt.*;
import javax.swing.*;

public class LoginFrame extends JFrame
{
XYLayout layout;
javax.swing.JPasswordField Password;

public LoginFrame(String args[])
{
layout = new XYLayout(369,151,0);
getContentPane().setLayout(null);
setVisible(false);
setSize(369,151);
setFont(new Font("Dialog",Font.PLAIN,12));
setBackground(new Color(12632256));
Password = new javax.swing.JPasswordField();
Password.setEchoChar('0');
Password.setBounds(100,39,208,22);
getContentPane().add(Password);

getContentPane().setLayout(layout);
layout.add(100,39,208,22,Password);
}

public void setVisible(boolean b)
{
if(b)
{
setLocation(300,300)
}
super.setVisible(b);
}
}

/* Code for MainPrg.java */
public class MainPrg
{
static public void main(String args[])
{
LoginFrame login = new LoginFrame(args);
login.setVisible(true);
//login.repaint() // didnt work
//login.validate() // didn't work - only blank frame at the start
}
}

I hope this helps.

Thanks
Bharath S
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't recommend XYLayout and all those explicit numbers. Have you tried just using a JOptionPane to display your password field?
 
Bharath Sekar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeff for your suggestion. But the problem exists only in certain windows XP machine. so I wud attribute this to the xp machine. Will get back soon. Thanks

Bharath S
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bharat,

It is working properly on Windows XP also.

Try to check again,

Regards,

import javax.swing.*;

public class MainPrg extends JFrame
{
public static void main(String args[])
{
LoginFrame login = new LoginFrame(args);
//login.setVisible(true);
//login.repaint() // didnt work
//login.validate(); // didn't work - only blank frame at the start
login.show();

}
}

Enable any one statement and run; it worked for me.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic