Java: repaint() Waking Nightmare

You know those times, while coding, when it feels like you’ve drifted into a horrible nightmare where nothing you do works?

This happened to me today.

I wanted the little app I’m making to display a green tick or a red cross depending on whether the user had entered valid credentials. Simple? Yeah. Everything went really well, I extended a JPanel to handle the tick/cross display area (tickCross), got the POST code going, strung together the rest of the GUI elements.

The problem was that tickCross.repaint() wasn’t reliably repainting. about 30% of the time the image wouldn’t be painted. The method was being called, but nothing was happening. I tried Google, re-read the related Sun Java docs and was reminded that: “repaint() does not actually paint. It calls the peer repaint which enqueues a request in some platform-dependent way inside the native GUI for a repaint.” – MindProd. Great. My OS was deciding when I was allowed to draw.

Somewhat more irritated, I then had to resort to every programmer’s backup tool: trial and error.

Thanks Rob (we make websites), for laughing at this post and emailing me the following:

tickCross.repaint();
tickCross.setVisible(false);
tickCross.setVisible(true);

?! How about:

Invalidate();

I swear I tried that, honest!


After much frustration, I struck a solution. It’s not elegant, I’d even say it’s hacksih, but it works.

1
2
3
tickCross.repaint();
tickCross.setVisible(false);
tickCross.setVisible(true);

Cross or tick when I damn well want them, every time.

Like this post? Move it on along with:

email Email | delicious delicious | digg Digg | Tweet this post Tweet | reddit Reddit | newsvine Newsvine | furl Furl | google Google | StumbleUpon Stumble | Hao Hao HaoHao


Trackback:

Comments: 0 | Comments Feed

Scroll to post title

No commentsTrackback

Find and Replace Text Within Multiple Files in Linux – Avoid RSI

After updating 100+ pages manually, I realized that I had neglected to add “index.php” to the end of certain links. Usually this would be fine, but the links in question are opened in Shadowbox, which will fail on pretty, “index.php”-less links.

I was able to fix this on the server in 5 seconds with find+perl:

find . -name 'FILE_NAME.EXTENSION' | xargs perl -pi -e 's/FIND/REPLACE/g'

Where FILE_NAME is the name of the files to be searched in (can be ‘*’) and EXTENSION is the filetype (can be ‘*’). FIND is the text to be searched, and REPLACE is a replacement string.

Phew!

Like this post? Move it on along with:

email Email | delicious delicious | digg Digg | Tweet this post Tweet | reddit Reddit | newsvine Newsvine | furl Furl | google Google | StumbleUpon Stumble | Hao Hao HaoHao


Trackback:

Comments: 0 | Comments Feed

Scroll to post title

Comments (1)Trackback

Rescuing Settings From Broken JDownloader Installation in Ubuntu

Somehow I broke my JDownloader installation, I think by meddling with the network settings. Nothing would download, and the auto-update was borked. I decided to delete it and reinstall it, but I had quite a lot of download packages queued, and wanted to rescue them. I managed to do this successfully, here’s how:

Locate the “backup” folder, in JDownloader’s root directory. For me, as I used this method to install JDownloader, the folder was in “/opt/JDownloader/”. Find the most recent “backup.zip” file. Note that there may be some numbers between “backup” and “.zip”. In Ubuntu’s default file manager, Nautilus, one can select “List View” and then click “Date Modified” to easily find the most recent file.

Copy this file and paste it to your desktop.

Create a new folder on your Desktop, call it “BACKUP”. Copy all files in JDownloader’s root directory into this folder.

Follow these instructions to install JDownloader. You can skip the “sudo mkdir /opt/JDownloader” step if you installed JDownloader with this method.

When JDownloader is installed, extract the “backup.zip” file you copied to your Desktop and modify then execute the following in a terminal:

sudo mv ~/Desktop/database.script /opt/JDownloader/config/database.script
sudo mv ~/Desktop/database.properties /opt/JDownloader/config/database.properties

Open JDownloader.

Your packages should have been restored. If you’re happy with the new installation, you can go ahead and delete the “BACKUP” folder.

Like this post? Move it on along with:

email Email | delicious delicious | digg Digg | Tweet this post Tweet | reddit Reddit | newsvine Newsvine | furl Furl | google Google | StumbleUpon Stumble | Hao Hao HaoHao


Trackback:

Comments: 0 | Comments Feed

Scroll to post title

No commentsTrackback

jQuery Error: ‘g is undefined’

Discovered the cause of this annoying (but seemingly impotent) error in a response by Karl Swedberg on Nabble.

The error was caused by my passing only one function to jQuery.hover(), eg:

 jQuery(".blog-entry-date").hover(function(){
                jQuery(this).animate({color: genHex()},100);
        });

Hover takes two functions. Instead ‘mouseenter’ should be used:

 jQuery(".blog-entry-date").bind('mouseenter',function(){
                jQuery(this).animate({color: genHex()},100);
        });

The error didn’t seem to have any effect on the execution of the code (at least in Firefox), but errors are errors, and the the cause should be hunted down. Always.

Like this post? Move it on along with:

email Email | delicious delicious | digg Digg | Tweet this post Tweet | reddit Reddit | newsvine Newsvine | furl Furl | google Google | StumbleUpon Stumble | Hao Hao HaoHao


Trackback:

Comments: 0 | Comments Feed

Scroll to post title

No commentsTrackback

No Sound in Ubuntu Jaunty With Intel HDA VT1708B

After becoming terminally annoyed with a my broken Intrepid installation, I decided to install Jaunty.

While I was enjoying the new growl-esque notification system, I noticed a flaw – no program would make any. Not a peep.

Headphones plugged in, check. Volume sliders in gnome-sound-properties all the way up, check. Hmm… Restart. Same. Uh… Reinstall. Nope.

So I tried everything Google could throw at the problem, to no avail.

After a day of mashing my fingers on the keyboard I gave up and resigned myself to code in silence.

It took me an hour to start searching for a solution – I found this thread: after Jaunty upgrade, no sound exept from OSS. There was no solution there, but happy to have found other to share my plight, I posted.

Post #9 was my solution.

For some reason “Independ” was turned “ON” in alsamixer. Switching this to “OFF” resulted in sound. WTF? I don’t know either. Nor do I care, as I now have sound.

Included is a screenshot of the section of alsamixer that needed punching:

Alsamixer Options

To see the relevant option in a normal sized Terminal window I had to press right a few times.

Like this post? Move it on along with:

email Email | delicious delicious | digg Digg | Tweet this post Tweet | reddit Reddit | newsvine Newsvine | furl Furl | google Google | StumbleUpon Stumble | Hao Hao HaoHao


Trackback:

Comments: 0 | Comments Feed

Scroll to post title

No commentsTrackback

Shadowbox rel=’shadowbox’ Doesn’t Work? Here’s a Workaround

Yesterday I was trying to implement a Shadowbox contact form in the Bay of Islands SPCA site, but I just couldn’t get it to work. I was using the standard setup that works perfectly well on the Te Kuiti SPCA Site:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<script type="text/javascript" src="http://tekuitispca.org/sb/jquery-1.2.3.min.js"></script>
<script type="text/javascript" src="http://tekuitispca.org/sb/shadowbox-jquery.js"></script>
<script type="text/javascript" src="http://tekuitispca.org/sb/shadowbox.js"></script>
<script type="text/javascript">
 
Shadowbox.loadSkin('classic', 'http://tekuitispca.org/sb/skin');
Shadowbox.loadLanguage('en', 'http://tekuitispca.org/sb/lang');
Shadowbox.loadPlayer(['iframe'], 'http://tekuitispca.org/sb/player');
 
window.onload = function(){
 
    var options = {
        initialWidth:     '0',
        initialHeight:    '0'
    };
 
    Shadowbox.init(options);
    }
 
</script>

And the HTML:

<a href="http://www.tekuitivets.co.nz/" rel="shadowbox;initialHeight=0;initialWidth=0;width=900;height=700;" title="Atkinson &amp; Associates Vet Clinic">Atkinson &amp Associates Vet Clinic</a>

I uploaded all the files, changed the addresses in the above code. Strangely, it worked find in Rapid Weaver, but not in Safari, Firefox, Epiphany or any other browser – either in export mode or after a full upload. My search for “Shadowbox just won’t work!” yielded no results, so was forced to use the programmer’s final weapon – exhaustive trial and error.

I tried various things for about an hour, and finally struck gold with this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<script type="text/javascript" src="http://boispca.org/sb/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="http://boispca.org/sb/shadowbox-jquery.js"></script>
<script type="text/javascript" src="http://boispca.org/sb/shadowbox.js"></script>
<script type="text/javascript">
 
	Shadowbox.loadSkin('classic', 'http://boispca.org/sb/skin');
	Shadowbox.loadLanguage('en', 'http://boispca.org/sb/lang');
	Shadowbox.loadPlayer(['iframe'], 'http://boispca.org/sb/player');
 
	jQuery(document).ready(function(){
 
		var options = {
		initialWidth:     '0',
		initialHeight:    '0'
		};
 
		Shadowbox.init(options);
 
		jQuery("#contact-us").click(function(){
			Shadowbox.open({
			        player:     'iframe',
			        title:      'Contact Us',
			        content:    'http://boispca.org/contact/',
			        height:     500,
			        width:      400
			    });
		    return false;
		});
	});
 
</script>

And HTML:

<a href="http://boispca.org/contact/" id="contact-us" title="Contact" >Contact</a>

Now whenever one clicks the contact button, Shadowbox is called through jQuery.

I don’t know why the normal way didn’t work!

Like this post? Move it on along with:

email Email | delicious delicious | digg Digg | Tweet this post Tweet | reddit Reddit | newsvine Newsvine | furl Furl | google Google | StumbleUpon Stumble | Hao Hao HaoHao


Trackback:

Comments: 0 | Comments Feed

Scroll to post title

No commentsTrackback