Problem about canvas repaint!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
class DrawPie extends Canvas{
Container cont;
public DrawPie(Container parent){
cont=parent;
public void addinContainer(){
this.setSize(200,200);
cont.add(this,BorderLayout.SOUTH);
public void paint(Graphics g){
g.drawString("This is test",20,20);
public class WelFrame extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
// Construct the frame
public WelFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
catch (Exception e) {
e.printStackTrace();
// Component initialization
private void jbInit() throws Exception {
Button btn=new Button("Open");
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btn_actionPerformed(e);
contentPane.add(btn,BorderLayout.NORTH);
this.setTitle("Welcome to JBuilder");
this.setSize(new Dimension(400, 300));
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
//File | Exit action performed
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
void btn_actionPerformed(ActionEvent e) {
DrawPie dp=new DrawPie(contentPane);
dp.addinContainer();
public static void main(String[] args){
WelFrame wf=new WelFrame();
wf.show();
I can't get the text painted when click the button open.But when i resize the Frame,the text appeared.
how can i get the text painted when i click the button open.Thanks a lot.

When you add a component to another component, call it the parent component, AFTER YOU HAVE CONSTRUCTED THE PARENT COMPONENT, you need to call the method validate()on the parent component to insure that this component, the parent component, has a valid layout. In your code, you're adding your component which extends Canvas to the parent component which extends JFrame AFTER instanciating it. Hence, you need to call validate() on this parent right after adding the child component. In other words, your method btn_actionPerformed should look like the following:
void btn_actionPerformed(ActionEvent e) {
DrawPie dp=new DrawPie(contentPane);
dp.addinContainer();
validate(); //or this.validate();
calling validate() will insure re-arrenging all children correctly according to the parent layout. When you resize your form, validate is called automatically and that's why the child component shows up.
Without calling validate(), your newly added child component is not resized and located according to the parent layout. it's probably with the size 0,0 and that's why you're not seeing the text.
I hope I explained it clearly enough

Similar Messages

  • Problem with window repaint and scrollbars in edit mode (LabVIEW 8.0.1)

    I am running LabVIEW 8.0.1 in Windows XP SP3.  For my main VI, I ran into a strange problem about 5 months ago.  The front panel window - in both edit mode and run mode - stopped repainting itself on the right side which is most visible when you scroll up and down, but also visible with overlapping windows.  Coincident with the repaint problem, both scrollbars look disabled with greyed-out arrows and no boxes in the bars that you can click and drag to scroll the window.  The scrollbars still partially work if you hover the mouse over them and roll the mouse wheel but clicking and dragging doesn't work. 
    The front panel has lots of controls and indicators including tab-control containers and is larger in the horizontal and vertical directions so both scrollbars should be active.  But I deleted all elements on the front panel and everything in the block diagram and the problem persists.  So the problem is not directly related to some control/indicator display.
    I saved the simple VI with this problem (using a wide text line and a tall rounded box to test), then created a new VI and copied the two elements to the new VI.  This new VI does not have the repaint and scrollbar problem.  The two VIs differ slightly in memory usage and in revision number (the bad one is revision 1785 and the good one is revision 3), but otherwise the two VIs are identical.  I attached both VIs to this posting.  When you first open the bad VI, you'll see the disabled scrollbars whereas the good VI has active scrollbars.  To replicate the repaint problem, scroll the window up and down with your mouse wheel.  If it's fine when you first open the VI, click on another window, then click back on the VI window and try the mouse wheel again.  This clicking-away-and-back always causes the repaint problem for me.  I tried the VIs on two different computers both running Windows XP SP3 and LabVIEW 8.0.1 with identical results.
    Here's what I discovered from troubleshooting with the simple VIs:
    * scrollbars always disabled
    * repaint problem in main window for window widths larger then 680 pixels
    * repaint problem in main window menu toolbar for widths larger than 646 pixels
    * entire window becomes disabled for window widths larger than 1348 pixels
    * can repaint window by minimizing and restoring, but only repaints that one time
    * scrollbar boxes sometimes flicker into view but then disappear
    * scroll left and right by hovering mouse over horizontal scrollbar and using mouse wheel
    I found something similar on this forum (thread: Problem with front panel refresh) - it might be related to the CAR about the panel being offset internally.  I don't have access to LabVIEW 8.5 or later and don't plan to upgrade - I haven't tried the trial version as that user did.  I could try to copy and paste my entire block diagram to a new VI but the VI is so large I'm afraid something would break, plus I don't want this to happen again in a few months.  The problem seemed to occur after a certain number of saves (or revision number).  I save backup copies often and when the problem first happened, I was able to go back to a previous version, make the missing changes and save it with no problems, but this only delayed the problem and it came up later.  So maybe it's the revision number.  It didn't seem related to a particular addition or modification in the front panel or diagram.
    The image attached shows the repaint and scrollbar problems in the bad VI.
    This brings up a question I have - if this problem is a bug and was fixed in 8.5 and later, is there a way to apply bug fixes to earlier versions?  Or do I have to pay for an upgrade to fix such bugs?
    Solved!
    Go to Solution.
    Attachments:
    RepaintTest_Bad.gif ‏27 KB
    Test Repaint - From Bad VI, scrollbar and repaint problems.vi ‏7 KB
    Test Repaint - From Blank VI, no problems.vi ‏5 KB

    Seems something got corrupted with this VI. Copy things over to a fresh VI and things should be OK.
    See also this recent report of a similar issue.
    LabVIEW Champion . Do more with less code and in less time .

  • An old and difficult problem about "UnsatisfiedLinkError"

    Hi dear all,
    I have been struck with the problem about "UnsatisfiedLinkError". I have a c++ class HelloWorld with a method hello(), and I want to call it from within a java class. In fact, I have succeeded in calling it on the windows platform. But when I transfer it to linux, the error "UnsatisfiedLinkError" comes out. I have tried to take the measures as Forum has suggested, but it failed.
    The source code is very simple to demonstrate JNI.
    "HelloWorld.h"
    #ifndef INCLUDEDHELLOWORLD_H
    #define INCLUDEDHELLOWORLD_H
    class HelloWorld
    public:
    void hello();
    #endif
    "HelloWorld.cpp"
    #include <iostream>
    #include "HelloWorld.h"
    using namespace std;
    void HelloWorld::hello()
    cout << "Hello, World!" << endl;
    "JHelloWorld.java"
    public class JHelloWorld
    public native void hello();
    static
    System.loadLibrary("hellolib");
    public static void main(String[] argv)
    JHelloWorld hw = new JHelloWorld();
    hw.hello();
    "JHelloWorld.cpp"
    #include <iostream>
    #include <jni.h>
    #include "HelloWorld.h"
    #include "JHelloWorld.h"
    JNIEXPORT void JNICALL Java_JHelloWorld_hello (JNIEnv * env, jobject obj)
    HelloWorld hw;
    hw.hello();
    All the files are in the same directory and all the processes are under the dirctory:
    1. javac JHelloWorld.java
    2. javah -classpath . JHelloWorld
    3. g++ -c -I/usr/java/jdk1.3/include -I/usr/java/jdk1.3/include/linux JHelloWorld.cpp HelloWorld.cpp
    4. ld -shared -o hellolib.so *.o
    5. java -cp . -Djava.library.path=. JHelloWorld
    Exception in thread "main" java.lang.UnsatisfiedLinkError: no hellolib in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1349)
    at java.lang.Runtime.loadLibrary0(Runtime.java:749)
    at java.lang.System.loadLibrary(System.java:820)
    at JHelloWorld.<clinit>(JHelloWorld.java:7)
    Tried another measure:
    i) export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
    ii)java -cp . JHelloWorld
    The same error came out as above.
    I really don't know what is wrong with it.
    Would you like to help me as soon as possible?
    Thanks.
    Regards,
    Johnson

    Hi Fabio,
    Thanks a lot for your help.
    It is very kind of you.
    Regards,
    Johnson

  • A problem about calling Labview vi in VB

    Hi all:
    I meeting a problem about data transfer and parallel operation between VB and Labview.
    Actually, I want develop a VB program, in which, the Labview VI can be called and corresponding parameters can be transferred to Labview. and then, I also can operate my system by VB program at same time. something like parallel operation (VB and Labview program).
     But the question is :
    1.   If I use "Call" method of ActiveX in VB,  and the LabVIEW subvi is not stopped (for example, a loop structure), I can not do  parallel operation on VB program. The error message is "other application is busy" which is attached below. The sample codes is also attached.
    2.   I tried to use other methods like "OpenFrontPanel" and "Run", but I am not sure how to transfer the parameter??
    3.  Then I tried to use "SetControlValue" to set the parameters, but there is a error " := expected", which is very strange, because the statement  I wrote is followed with the help documents [ eg: VI.SetControlValue ("string", value)], why it is still need a "=" ??
    Does anybody know something about it? Thanks a lot
    Message Edited by hanwei on 11-07-2008 03:18 PM
    Attachments:
    vb_labview_error_message_1.JPG ‏14 KB
    VB_to_LV.zip ‏10 KB

    I sure hope OP has solved it by now.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • HT201210 hi everyone, i have a problem about my iphone 4S, doesn't work with wifi connection and bluetooth since upgrade to the IOS 7.0.3. Can anyone can help me tosolve this problem?????Thank's regards paulus

    hi everyone, i have a problem about my iphone 4S, doesn't work with wifi connection and bluetooth since upgrade to the IOS 7.0.3. Can anyone can help me tosolve this problem?????Thank's regards paulus

    Try the suggestions here to see if they resolve your problem:
    http://support.apple.com/kb/ts1559
    If these don't work you may have a hardware problem. Visit an Apple store for an evaluation or contact Apple Support.

  • Problem about Handling of Empty Files in File Adapter

    Hello everyone,
    NetWeaver 2004s --- XI
    In Sender i have a File Adapter.
    Now i meet a problem about Handling of Empty Files. When i send empty file, but don't cerate a leer message.
    I have seen following text in help document. But in adapter configuration i can not find the correspond parameter.
    can you give me some tips?
    Thx in advance
    best regards
    Yaning
    SAP Help Document über File Adapter
    +Handling of Empty Files
    Specify how empty files (length 0 bytes) are to be handled.
    &#9675;       Do Not Create Message
    No XI messages are created from empty files.
    The files are processed according to the selected Processing Mode.
    For example, if the processing mode is Delete, empty files are deleted in the source directory.
    &#9675;       Process Empty Files
    XI messages are created with an empty main payload.
    The files are processed according to the selected Processing Mode.
    &#9675;       Skip Empty Files
    No XI messages are created from empty files.
    Empty files are skipped and remain in the source directory.+
    Help Docu

    hi,
    it's available since Sp19 for XI 3.0
    and the corresponding SPS fpr XI 7.0
    http://help.sap.com/saphelp_nw04/helpdata/en/44/f565854b7341e6e10000000a1553f6/frameset.htm
    so probably you need to install the new SP
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

  • Problem about sales order stock stock transfer and batch determination

    Hi, experts, I get a problem about sales order stock stock transfer and batch determination.The following is the current situation of my system:
      In OMCG I assigned search procedure ME0001 to both 311 and 311 E and ticked check batch. After that, I found  that if iI need to tranfer unrestricted-use material from storage location 1000 to 2000 with movement type 311, I just need to input * at the field batch, then the system will display all of the available batches. But for the transferring of sales order stock with movement type 311 E, after I input * at the batch field, no batch is displayed and there is also no message from the system.
      Can anybody help me? Is there anything else I need to do? Thanks very much.

    I think my question is not clear, actually I tried 562 E , 411 E and 413 already. all the transaction looking for the sales order but unfortunatly the sales order is deleted  from SAP.

  • Hello apple I have the problem with my iPhone and my friends have this problem too. My iPhone have the problem about calling and answer the call. When I use my iPhone to call I can't hear anything from my iPhone but the person that I call can answer it bu

    Hello apple
    I have the problem with my iPhone and my friends have this problem too.
    My iPhone have the problem about calling and answer the call. When I use my iPhone to call I can't hear anything from my iPhone but the person that I call can answer it but when answer both of us can't hear anything and when I put my iPhone to my face the screen is still on and when I quit the phone application and open it again it will automatic call my recent call. And when my friends call me my iPhone didn't show anything even the missed call I'm only know that I missed the call from messages from carrier. Please check these problem I restored my iPhone for 4 time now in this week. I lived in Hatyai, Songkhla,Thailand and many people in my city have this problem.
    Who have this problem??

    Apple isnt here. this is a user based forum for technical questions. The solution is to restart, reset, and restore as new which is in the manual after that get it replaced for hard ware failure. if your within your one year warranty its replaced if it is out of the warranty then it is 199$

  • Problem about updating to Mac OS X 10.5.3

    Hi there,
    I just bought my Macbook two months ago. I encounted a problem about updating it to the latest version of MAC OS X. The system reminded me to restart, I proceed. Everythig looked just fine until a poping up window shown "Mac OS X 10.5.3 pacakage can not be validated". Dose anyone know what did that mean? How can I update my little mac?

    Hi Hummer,
    First, welcome to Apple discussions.
    To answer your question, your computer checks all downloaded updates before installing them. It does this to make sure it's got the entire file and that the update will install correctly. The fact that validation fails on your machine probably means the file did not download correctly.
    To install 10.5.3, simply go to this website, download the "10.5.3 combo update" and then run it on your Mac: http://www.apple.com/support/downloads/

  • Hardware diagnostic shows me a problem about charging battery. What about it ?

    Hi.
    I bought a MacBook Pro retina 13', mid 14. on last december, and after almost a month I did the hardware test of apple as the Technic support says, and this hardware test shows me a problem about charging battery, so, I wanna know what about it, is it normal ? or is it a battery problem or is it a problem about the Current adaptador ? Thank your for your answers.

    Could be battery, could be adaptor, could be the computer itself.  You will have to take it in for testing.  Fortunately, you are still under warranty.

  • The problem about vrrp

    Dear all,I have a problem about vrrp,my core switch is cisco 3750x and huawei S5700-28C-EI, after I configured vrrp between them,the switch log got the error problem as follow:
    *Jan 11 00:01:43.111: %VRRP-6-STATECHANGE: g1/0 Grp 3 state Backup -> Master
    *Jan 11 00:01:43.111: VRRP: tbridge_smf_update failed
    *Jan 11 00:01:44.187: VRRP: Advertisement from 10.252.200.34 has an incorrect group 10 id for interface g1/0
    *Jan 11 00:01:46.539: VRRP: Advertisement from 10.252.200.36 has an incorrect group 10 id for interface g1/0                
    *Jan 11 00:01:50.323: VRRP: Advertisement from 10.252.200.34 has an incorrect group 10 id for interface g1/0
    *Jan 11 00:01:51.707: VRRP: Advertisement from 10.252.200.36 has an incorrect group 10 id for interface g1/0
    *Jan 11 00:01:52.079: VRRP: Advertisement from 10.252.200.34 has an incorrect group 10 id for interface g1/0
    *Jan 11 00:01:53.079: VRRP: Advertisement from 10.252.200.34 has an incorrect group 10 id for interface g1/0
    If cisco and huawei cannot interconnect with each other?

    Can you post the interface config from the huawei and cisco device?
    HTH,
    John
    *** Please rate all useful posts ***

  • A problem about Chinese encoding

    When i access portal by SSL,I find one or two problems about encoding.
    reshow these problems:
    1. Locale be set to Chinese(zh_CN)
    2. access portal by SSL
    3. Administration/create portlet
    Then the popup window's title will show a bad encoding.
    otherwise,if i search chinese, then only have bad encoding shown in the searchbox and i can't get anything.
    MY running enviroment:
    windows 2003
    plumtree foundation v6.0
    plumtree publisher v6.2
    tomcat 5.0.58 with jre_1.4.2.08
    MSSql 2000 sp4
    and I have tried other BEA ALUI newer version,I can get these problems.
    I'm appreciated for any help.

    ANSI 0xFF is NBSP. NBSP in Unicode is 0x00A0... so neither 0x00FF (which is �) nor 0xF5F8 (which is in the "private use" range) is correct. Something really weird is going on.We are talking about CP1252 and in CP1252 0xFF is �
    (see http://czyborra.com/charsets/iso8859.html for example) and thus is \u00FF correct.
    btw. I would never use windows notepad as reference application.

  • A problem about EAX

    A problem about EAXX We have some problem in our development when using "Creative OpenAL SDK . (ver 3.03)". We create "OpenAL device" using "Generic Software"
    and play audio with EAX2.0. But the EAX effect works on one computer while it doesn't work on another one. Followings are the two computers' configuration:
    The computer which works well with EAX:
    Operation system: Windows XP SP3
    Motherboard chipset: Intel i945G
    Sound card: Creative Sound Blaster Audigy Digital Deluxe
    OpenAL.dll version: 6.4.0357.22
    Wrap_oal.dll version: 2..8.
    The computer which doesn't work with EAX:
    Operation system: Windows XP SP3
    Motherboard chipset: Intel i945GC
    Sound card: Creative Sound Blaster Audigy Digital Deluxe
    OpenAL.dll version: 6.4.0357.22
    Wrap_oal.dll version: 2..8.

    Hello gozhu_g,
    I suggest getting in touch with the developers on your inquiry. Here's their site.

  • Problem about space management of archived log files

    Dear friends,
    I have a problem about space management of archived log files.
    my database is Oracle 10g release 1 running in archivelog mode. I use OEM(web based) to config all the backup and recovery settings.
    I config "Flash Recovery Area" to do backup and recovery automatically. my daily backup schedule is every night at 2:00am. and my backup setting is "disk settings"--"compressed backup set". the following is the RMAN script:
    Daily Script:
    run {
    allocate channel oem_disk_backup device type disk;
    recover copy of database with tag 'ORA$OEM_LEVEL_0';
    backup incremental level 1 cumulative copies=1 for recover of copy with tag 'ORA$OEM_LEVEL_0' database;
    the retention policy is the second choice, that is "Retain backups that are necessary for a recovery to any time within the specified number of days (point-in-time recovery)". the recovery window is 1 day.
    I assign enough space for flash recovery area. my database size is about 2G. I assign 20G as flash recovery area.
    now here is the problem, through oracle online manual, it said oracle can manage the flash recovery area automatically, that is, when the space is full, it can delete the obsolete archived log files. but in fact, it never works! whenever the space is full, the database will hang up! besides, the status of archived log files is very strange, for example, it can change "obsolete" stauts from "yes" to "no", and then from "no" to "yes". I really have no idea about this! even though I know oracle usually keep archived files for some longer days than retention policy, but I really don't know why the obsolete status can change automatically. although I can write a schedule job to delete obsolete archived files every day, but I just want to know the reason. my goal is to backup all the files on disk and let oracle automatically manage them.
    also, there is another problem about archive mode. I have two oracle 10g databases(release one), the size of db1 is more than 20G, the size of db2 is about 2G. both of them have the same backup and recovery policy, except I assign more flash recovery area for db1. both of them are on archive mode. both of nearly nobody access except for the schedule backup job and sometime I will admin through oem. the strange thing is that the number of archived log files of smaller database, db2, are much bigger than ones of bigger database. also the same situation for the size of the flashback logs for point-in-time recovery. (I enable flashback logging for fast database point-in-time recovery, the flashback retention time is 24 hours.) I found the memory utility of smaller database is higher than bigger database. nearly all the time the smaller database's memory utility keeps more than 99%. while the bigger one's memory utility keeps about 97%. (I enable "Automatic Shared Memory Management" on both databases.) but both database's cup and queue are very low. I'm nearly sure no one hack the databases. so I really have no idea why the same backup and recovery policy will result so different result, especially the smaller one produces more redo logs than bigger one. does there anyone happen to know the reason or how should I do to check the reason?
    by the way, I found web based OEM can't reflect the correct database status when the database shutdown abnormally. for example, if the database hang up because of out of flash recovery area, after I assign more flash recovery area space and then restart the database, the OEM usually can't reflect the correct database status. I must restart OEM manually to correctly reflect the current database status. does there anyone know in what situation I should restart OEM to reflect the correct database status?
    sorry for the long message, I just want to describe in details to easy diagnosis.
    any hint will be greatly appreciated!
    Sammy

    thank you very much, in fact, my site's oracle never works about managing archive files automatically although I have tried all my best. at last, I made a job running daily to check the archive files and delete them.
    thanks again.

  • A switch on/off problem about the relay in a loop

    hi group:
    I am developing a project based the Ni-sci-1160. Now I meet a problem about switch on/off in a loop.
    for example:  I creat a loop, and continually check a boolean. if the boolean is true, then the realy is closed, otherwise the relay is open. The problem is when I make the boolean is true,  the corresponding relay is not always on,  but just on-off, on-off,on-off.  I don't know why? Is there any good idea to fix it?
    the easy example codes is attached here , thanks for you help.
    Attachments:
    relay_problem.vi ‏19 KB

    Try moving that first DAQmx function out of the while loop.  Since it is called switch set and Reset, I'm guessing it is resetting the status of the switch every iteration of the while loop which probably means setting it back to false.  It looks like an initialization type of function which means it should only be run once.

Maybe you are looking for

  • Two sided printing on HP with Yosemite no longer available?

    Since updating my iMac to the latest Yosemite, (10.10.2) my HP all in one C6280 printer does not even offer the option of two sided printing.  Is there a way to get this feature back? The printer used to do two sided printing, and the option used to

  • Multiple text blocks in PDF

    The PDF I created from InDesign is making 3 text blocks per line! My client needs to edit his menu. Almost every word is a text block. It's only one text block in the InDesign file. I'm using CS6.

  • Requisition Release Procedure No longer working

    Hi expert! My client raised an incident regarding the PR release strategy. Their Requisition Release procedure is based on document type.The user that is creating the requisition has the option of choosing document type NB (Non Release Requisition) o

  • Excise procedure

    Dear experts, I have a scenario on which I need some guidance. 1. we have a storage location that is outside the plant premises. 2. any material that comes to the sloc is transferred to the plant and then the excise posting is done. 3. till the time

  • Fraction Problem in Freehand

    When making a fraction in FreeHand MX, using Futura Condensed, I get a font substitution to Symbol for the virgule. This does not happen in Illustrator and QuarkXPress. Converting to paths solves the problem, but is not practical. Anyone else getting