File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes how to see button in an applet ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to see button in an applet ?" Watch "how to see button in an applet ?" New topic
Author

how to see button in an applet ?

Mahesh Bhatt
Ranch Hand

Joined: Sep 15, 2004
Posts: 88
Hi all,
I have an applet in which i call a method from my paint() method to add two buttons, the paint() method transfers control to the method and i get the two buttons on the applet screen but i can see those only if I enlarge the applet screen, otherwise the screen is blank . I am giving the code below :
[code]

public void afterQuestions(){
remove(okbutton);
remove(answerField);
add(reviewbutton); //this is the first button
add(scorebutton); //this is the second button

stopflicker=false;
}

after this method i should ideally see the buttons in my applet on the top-centre ..


Impossible is I M Possible
Mehul Sanghvi
Ranch Hand

Joined: Feb 04, 2002
Posts: 134
Hi,

Following one of the following sequences should do the trick

Sequence 1:
applet.add(button);
applet.show();

OR

Sequence 2:
applet.show();
applet.add(button);
applet.repaint();

Hope this helps.

Regards,
Mehul K. Sanghvi.
Mahesh Bhatt
Ranch Hand

Joined: Sep 15, 2004
Posts: 88
Hi mehul,
Sorry, but that didn't work .I can Still see those buttons if :
1) I double click on the top most part of the window.( as we do to enlarge the window to fit into full screen ).
2) I click the edge of the window and drag the mouse ( as we do to increase the size of a window);
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Mehul's reply has more to do with how to show the applet in the first place, but what you're doing is changing the components contained in an applet that's already on-screen. Whenever you remove and/or add components to a visible container, you have to call validate() on the container -- in this case, the applet. validate() tells the layout manager that you're done making changes, and the layout should be recalculated. The screen will be repainted automatically.

This belongs in our Swing/AWT/SWT forum, so I'm moving it over there for any further discussion.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to see button in an applet ?
 
Similar Threads
Graphics without paint() method
Switching between panels in a GUI
invisible canvas
an awt question
JSlider not displaying