Dynamically create a button, but what happened?
I am new to Swing GUI, and I want to create a new button in a panel named centerPanel, so my code like this:
public class TestButton extends JFrame {
public static void main(String args[]) {
try {
TestButton frame = new TestButton();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
public TestButton() {
super();
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel center = new JPanel();
getContentPane().add(center, BorderLayout.CENTER);
final JPanel south = new JPanel();
getContentPane().add(south, BorderLayout.SOUTH);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
JButton newbutton = new JButton("Heeeeeeeee");
center.add(newbutton);
center.repaint();
button.setText("New JButton");
south.add(button);
}but why this does not work, I can not see it? Please give me a hand, thanks in advance!
Call center.revalidate () after add (...), not center.repaint ().
db
edit Just noticed who the question was addressed to, thought I'd clarify that I'm not really authorized to answer on His behalf.
Edited by: Darryl.Burke
Similar Messages
-
what will i do with my ipad 2 ios 5.0.1 stuck on white apple logo and itunes not recognized it. i'll always try to press and hold both the home botton and sleep/wake button but nothings happen.
if that dose not work then you can always put it into DFU mode by connecting to your computer and holding down the home button and sleep/wake button for excatly 10 seconds and then relesing the sleep/wake button and keep holding down the homebutton till iTunes tells you it has detected an iPad in recovery mode then just do a restore
-
Creating a Function logic for dynamically created XML buttons
Hi!
It's me...... again! Now I've dynamically created some buttons using XML. They're spread around the stage and I've modified a tooltip script to give each button a tooltip on Mouse_Over. But to se the logic and make it work using AS3 is hard (for me). I want a function that accept to parameters: Tooltip text and Object to tooltip.
In my code I get this error msg when initiating the function on dynamically created buttons:
1118: Implicit coercion of a value with static type flash.display:Sprite to a possibly unrelated type flash.display:MovieClip.
I beleive there are more than one thing here needing a fix.
Can someone have a look and give me a pointer?
Thanks
function contentTooltip(ttt:String, ttclip:MovieClip):void {
ttclip.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
function mouseOverHandler(e:MouseEvent):void {
ttip.descr.text=ttt;
ttip.x=stage.mouseX;
ttip.y=stage.mouseY-15;
ttclip.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
ttclip.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
ttip.visible = true;
function mouseOutHandler(e:MouseEvent):void {
ttip.visible = false;
ttclip.removeEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
ttclip.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
function mouseMoveHandler(e:MouseEvent):void {
ttip.x=stage.mouseX;
ttip.y=stage.mouseY-15;
contentTooltip("Scale button",scale_btn);
contentTooltip("Hide button",hide_btn);I totally agree with what Ned says and suggests. Nevertheless, I would like to support your thinking process.
From the way you wrote the tooltip functionality it is apparent to me that you conceptualize as a programmer. Again, as Ned said, nested functions are evil. BUT, in a way, what classes accomplish is encapsulation/nesting of properties and functions under the same umbrella. It actually feels that what timeline does in general is nesting named functions within a single function we have no access to.
How you wrote the code is actually a blueprint for a class that could handle the functionality. You, perhaps, are very ready to start coding with classes - not on the timeline.
With that said, for the sake of theory, here is how your functionality can be rewritten on timeline:
scale_btn.toolTip = "Scale button";
test_btn.toolTip = "Test button";
hide_btn.toolTip = "Hide button";
scale_btn.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
test_btn.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
hide_btn.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
var overTarget:MovieClip;
function mouseOverHandler(e:MouseEvent):void {
overTarget = e.currentTarget;
ttip.descr.text = overTarget.toolTip;
ttip.x = stage.mouseX;
ttip.y = stage.mouseY - 15;
overTarget.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
overTarget.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
setChildIndex(ttip, numChildren - 1);
ttip.visible = true;
function mouseOutHandler(e:MouseEvent):void {
ttip.visible = false;
overTarget.removeEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
overTarget.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
function mouseMoveHandler(e:MouseEvent):void {
TweenMax.to(ttip, .5, { x:stage.mouseX, ease:Quart.easeOut } );
TweenMax.to(ttip, .5, { y:stage.mouseY - ttclip.height / 2, ease:Quart.easeOut } );
//ttip.x=stage.mouseX;
//ttip.y=stage.mouseY-ttclip.height/2; -
I can't delete a song from on-the-go playlist. I've got a classic 80gb. I've held down the button but nothing happens. Any suggestions?
bostonshazzer,
What model iPod do you have? This feature is not supported on all models. You are positive you are holding down the Select (Center) button with the song highlighted until it disappears? Are you sure you are in your On-the-Go playlist and not just a regular one?
B-rock -
While trying to update my Ipad to the new operating systemm my screen is stuck on the "Terms and Conditions" screen. I tried touching the "agree" button and the "send my email" button, but nothing happens. I can't get out of the screen without missing my full update. Please help.
completely switch off your ipad with pressing the top power button really long and then swipe the red swiper at the top. Then turn your ipad back on, skip the icloud login screen and you should be good! That's what i did so should work for you too
-
I am having trouble downloading Premier Pro, as i click the download button but nothing happens why is that?
Do you have a 64bit computer, and what is it?
Link for Download & Install & Setup & Activation problems may help
-Chat http://www.adobe.com/support/download-install/supportinfo/
OR
Some download & install troubleshooting links
-Comodo Security kills download http://forums.adobe.com/thread/1460361?tstart=0
-http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html
-http://helpx.adobe.com/creative-cloud/kb/error-downloading-cc-apps.html
-http://forums.adobe.com/community/download_install_setup
-http://helpx.adobe.com/creative-cloud/kb/troubleshoot-cc-installation-download.html
-http://helpx.adobe.com/x-productkb/global/errors-or-unexpected-behavior-websites.html
-http://helpx.adobe.com/creative-cloud/kb/unknown-server-error-launching-cc.html
-Server won't connect https://forums.adobe.com/thread/1233088
-SPECIAL FOR MAC USERS
-Mac 10.9.3 workaround https://forums.adobe.com/thread/1489922
-more Mac 10.9.3 https://forums.adobe.com/thread/1491469
-Enable Mac Root User https://forums.adobe.com/thread/1156604
-more Root User http://forums.adobe.com/thread/879931
-and more root user http://forums.adobe.com/thread/940869?tstart=0 -
I want to change my Apple ID because I have a new email address, but what happens when someone tries to facetime me using my old Apple ID? Will they still be able to contact me on facetime using my old Apple ID?
Not if you change the ID. You would need to give them the new address.
-
how to transfer files like music from mac to ipad? tried it few times but what happen was the opposite.
If you want to sync your iTunes library on your Mac to your iPad ....
Connect your iPad to the Mac and launch iTunes. Click on your iPad's name on the left side under the devices heading. Then click on the Music tab - and select the music that you want to transfer. Does your iTunes window look like this - with Sync Music checked and the playlists or albums checked as well like in the photo below?
When you click on the apps tab do you have Sync Apps checked and all of the apps in the window below checked to sync as well?
If you select all of the items under the different tabs in iTunes - music, apps, photos. etc. - when you sync - all of the selected content should sync over to the iPad. -
I'm running Safari 6.0.5 - Mac OS 10.8.4 -- when I load my gmail the block around the DELETE and MOVE tabs are not usable - press buttons but nothing happens. ???
I can see the block (flashes) and the buttons are no longer usable.
I have Empted Cache but doesn't seem to help.From the Safari menu bar, select
Safari ▹ Preferences ▹ Extensions
Turn all extensions OFF and test. If the problem is resolved, turn extensions back ON and then disable them one or a few at a time until you find the culprit.
If you wish, you may be able to salvage the malfunctioning extension by uninstalling and reinstalling it. Its settings will revert to their defaults. If the extension still causes a problem, remove it permanently or refer to its developer for support. -
Mountain Lion will not download. App just says "download" on purchase button, but nothing happens. Any ideas?
My download took many many hours. Not sure if that is because of our ISP or load on the network. I also thought nothing was happening for my download. Try this:
Open App Store,
click on Purchased
You'll see Mountain Lion being downloaded and it will show the progress and estimated time to complete.
Take deep breaths and be patient. -
Hi i'm from turkey.ios developer program license agreement page i'm clicking i agree button but nothings happen
I see - [Error] ReferenceError: Can't find variable: $$
canSubmit (licenseAgreement.js, line 19)
onclick (index.action, line 1)
var btnElements = $$('#submitBtn,#listAgreementForm_agreeButton'); ??? -
Clicked on Show or Hide HP Smart Web Printing button but nothing happened.
I Clicked on Show or Hide HP Smart Web Printing button but nothing happened. I tried uninstalling and reinstalling... and i am already in a 32 bit browser on an 84 bit operating machine with adobe flash player. Please send me some advice for problem shooting... Thank you all!
Hey HP ... Does anyone from HP monitor these posts and provide answers, as one might expect? Is anyone listening? Is anyone there? Does anyone CARE?
-
Was downloading the os 6.1.3 software and the iPad seems to have frozen. Have tried the off button but nothing happens. Doesn't indicate that the power is on.
Then try this now.
Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up. -
One of my contacts no longer has an icon for texting. It show the phone icon and his number is still present. I can still send and receive texts from this person but what happened to the "balloon" icon?
Can you delete the contact, reset your phone and then re add the contact again?
(982) -
How do I restore the icloud backup for my Ipad if I never set up the "back up" in the first place? My Ipad is in a frozen state. I press the OK button but nothing happens. The message on the iPad is "iCloud Backup This iPad hasn't been backed up in 2 weeks. Backups happen when this iPad is plugged in, locked, and connected to Wi-Fi."
Perform a Reset...
Reset ( No Data will be Lost )
Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
http://support.apple.com/kb/ht1430
Maybe you are looking for
-
CC field in email using SO_NEW_DOCUMENT_ATT_SEND_API1
Hi, im using FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send email and it works fine. my problem is i dont know how to fill the 'CC' field of my email, im using MS Outlook by the way. thanks for your support!
-
Sql query slow from application but executes in 1 min in Toad
Hello, When I execute a big select query from DB itself , it gives results in a min. But when called from .Net application it takes 10 mins to execute. But after trying to excute no of times, it suddenly works faster sometimes.
-
Bridge mode for airport extreme or dsl modem? Recomendations?
I'm upgrading to a 'blisteringly fast' 12 Mbps with my local DSL ISP (no cable in my area), and I'm thinking of changing out my My current, antiquated setup is with a Speedstream 5200 Modem/Router (8 Mbps max) with a Linksys E1200 802.11n router. We
-
Error code :d0000029 while purchasing Cross court tennis 2 App in lumia
Error code :d0000029 while purchasing Cross court tennis 2 App in lumia , I tried so many times But it is not yet solved. Trial version is working fine, When i tried to buy full game at last movement it is returning error as d0000029
-
Windows XP laptop sees wireless network but won't connect
I set up a wireless network on my airport extreme using my MacBook. The McBook runs great on the wireless network. My old Dell laptop running Windows XP sees the wireless network I created (with full signal strength) but every time I hit "connect" I