473,799 Members | 3,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Swing problem

I haven't used Swing too much, but I've recently run into a problem
that I'm not sure how to fix. When I remove all components from a
JPanel and then add new components to it, the panel displays the new
components if they are AWT components, but not if they're Swing
components. Example

import java.awt.*;
import javax.swing.*;
public class test extends JFrame
{
public static void main(String[] args)
{
new test();
}
public test()
{
JPanel panel = new JPanel();
panel.add(new Button("a"));
panel.add(new Button("b"));
getContentPane( ).add(panel);
pack();
show();
try{Thread.slee p(3000);}catch( Exception ex){}
panel.removeAll ();
panel.add(new Button("c"));
panel.add(new Button("d"));
panel.repaint() ;
}
}

This works fine. But if I change Button to JButton everywhere, then
the panel goes blank after 3 seconds. Can anyone tell me why this
happens?

Thanks in advance
Jul 17 '05 #1
2 3528
Leo P. wrote:
[snip]
panel.repaint() ;
}
}

This works fine. But if I change Button to JButton everywhere, then
the panel goes blank after 3 seconds. Can anyone tell me why this
happens?


Leo,

Change the call to repaint() to revalidate(). Use revalidate() whenever
a component's lay out needs to be redone.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2
That works great. Thanks for answering my question even though I
accidentally posted it into someone else's thread

Raymond DeCampo <rd******@spam. twcny.spam.rr.s pam.com.spam> wrote in message news:<rc******* ***********@twi ster.nyroc.rr.c om>...
Leo P. wrote:
[snip]
panel.repaint() ;
}
}

This works fine. But if I change Button to JButton everywhere, then
the panel goes blank after 3 seconds. Can anyone tell me why this
happens?


Leo,

Change the call to repaint() to revalidate(). Use revalidate() whenever
a component's lay out needs to be redone.

HTH,
Ray

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11233
by: Rui Pacheco | last post by:
Hi I am developing an Swing applet. I am using Eclipse as my IDE and I am compiling the classes through the command line. Everything went ok, but suddenly it started to give the error "Package javax.swing not found in import." I searched Google groups and found that it's a classpath problem, but I can't seem to get it right. Can anyone help me? And why did it break all of a sudden, without any changes to the system? This is my...
5
13966
by: Chris | last post by:
Having been traumatised many years ago when using MFC/C++ to develop front-end code, I've religiously avoided GUI work since and stuck to back-end / server-side projects. So I'm a bit of a novice when it comes to designing Swing-based applications. I'm now having to do more and more GUI work to support my current projects, so I started looking for tutorial / best-practices materials on the net. I was somewhat surprised to find that...
6
6422
by: Joseph | last post by:
hi 1) i plan on having an awt canvas component (to draw graphs) on a JFrame with other swing components..will this be okay? i've read that swing and awt aren't compatible.. 2)Also, if i have a function which simply loops infinately that is part of a form, what happens when a form event (eg button click) occurs? will the event handler be executed simulatanesouly with the loop? or does the event excecute first and then the loop is...
3
4866
by: Sherrod Faulks | last post by:
I'm using Jython and in the python script I do: from javax import swing result = javax.swing.JOptionPane.showInputDialog(wC, cmd,"Prompt from " + client.serverName, JOptionPane.PLAIN_MESSAGE) wC is a JFrame, cmd is a String and client.serverName is a String. It won't show the JOptionPane, why?
1
2245
by: Nandan | last post by:
hello, can I ask a jython question here? when I use the jython interpreter I have no problem with the statement: from java import lang from javax import swing but when I put this in a script, I get a package not found error. what am I doing wrong?
1
4813
by: Parasol | last post by:
Hi I got a big problem. I'm using newest WindowBuildera 4.3.0 for Eclipse (newest too) on 1.5.06 JDK. I create new projekt, add any new Swing component and everything goes ok, but when I'm detaching to Design Mode a see "java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread". This problem occurs only when using Swing components (on SWT everything is ok). Have anyone similar problem ? Maybe somebody could me help...
0
3087
by: Andre Rothe | last post by:
Hi, Can anyone give me a recipe to handle the following problem: I try to use Observable in the data model class and Observer in the view class. But I'm unsure, how I can combine these with Swing model classes. Is it better to use only Swing or only Observer/Observable? In my view class (JFrame) I have a JListbox and if I select one entry, the view class calls a method of the data model and the model class notifies its observer (and...
6
51167
by: r035198x | last post by:
I have put together this article to give people starting Swing an awareness of issues that need to be considered when creating a Swing application. Most of the Swing tutorials that I have seen just help people display some nice widgets quickly without explaining some issues that need to be tackled when a full application needs to be developed. This article does not go into full implementation details because those can be found by reading the...
8
5699
risk32
by: risk32 | last post by:
Hi all. I have a really confusing problem. I'm using Swing and I'm trying to do a confirmation box : int reply; String message = "Do you want to input another number?"; String title = "Input Another Number?"; reply = (JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION); if (reply == JOptionPane.NO_OPTION) { System.exit(0); } This part works great, now down to business:
0
9688
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
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9078
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...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.