A Beginner’s Guide to Java Swing

For those looking for a quick introduction to laying out Graphical User Interface components using Java’s Swing technology, this guide may prove helpful. (But probably not.)

Swing Components all have a few common properties that affect how they are laid out on the GUI. These are:

  • alignmentX and alignmentY do nothing whatsoever.
  • maximumSize sets the largest size the component can be when rendered, unless the Layout Manager feels like messing with you.
  • minimumSize sets the smallest size the component can be, although this only holds when Venus is in Capricorn.
  • preferredSize sets the exact size that a component will try to be, provided you have entered the secret unlock codes which are known only to Larry Ellison and the Illuminati.

Swing components are arranged inside their parent panels by Layout Managers. Many layout managers are available to achieve certain common layouts. They include:

  • FlowLayout arranges components in a straight horizontal line, hiding any that it can’t be bothered to display because your box was too small for them.
  • BoxLayout places all components in either a horizontal or vertical line, expanding to fit them all, but resizing the child components for the lulz.
  • BorderLayout places components on the top, left, bottom or right-hand side of the panel. If you place two on the same side, they duel to the death until only one survives.
  • GridLayout arranges components in a grid with fixed size cells. If the component in one of the cells happens to be huge for some reason (e.g. you did not enter the Illuminati secret unlock code), your entire parent panel expands until it consumes the universe.
  • GridBagLayout represents the eternal influence of the Outer Gods in the affairs of man. Ï̷̫̥̣͈ͯ̌a̱̮̼̣̞͇̬͚ͧ́̉̆ͭͭ͜I̻̝̰̟͕̖͎ͦ̏ͫ̀͗̋͢ã̶̧̭͚͖ͤ͑́̎ͩͅ!̙͉͙̫̋̋͠ ̹͓̝̹͙͉̲͉̰́̽̐̈ͭ͆̎!̛̘̖̺̺̦̙ͦ͗̂͗̈͊͝
    f̦̬̲͇̥̗̙̬͆ͦͦ̀̒̕G̸̩̹̞̫̈ͨ͒͆͞r̶̤͆̋i̴̮͖̦̙̤͈̗͍̎͛ḑ̗̰̘̔ͥ͆͢B̻͇͎̣̰͓̀̇͒ͬ̈́͂ͣ̚͠͠ä̲̮̰͚̬͑̎́g̷̲͔̬͓̙̙̑̂ͧ͢L̶̛͍͎̝̲͐̃a̴͈̤̖͚̠̼̳̺̬͊ͥ̕͡ẏ̶̹̃̌͛̀ǒ̴̙̜̭͖̆͆ͮ̀ͫ͌ͤ͠u̶̥͈̝̱̺͖̔̿͗̊ͦ̒̋ͩ́t͖̤̻̥̟̻̻̹̞̻̎͒̅͂͗͑̽̎ͩ̇̇̔̉̌̃ ̵͕̘̬̳͆̒̈́ͭͦ̚͠’̷̘̔͋ͦ͂͝t͍͉͒̄ͨ̓ͧ̋̀h̲̣̜̱̳̝ͣ̓ą̶̸̜͎̝̹̭̹͒̐̄͊ͯ̐g̯̹̔̍ͦ͡n̩͚̞͆͌ͬ̐!̞̪͎͙̼͇͌͊̌

I hope that helps.

The Cautionary Tale of Sultan Hamnvik

That the car park was eerily futuristic, with automated sensors telling you how many spaces remained in each lane, should have been your first warning. No, yet earlier than that. You should have realised when it took you four attempts to leave the dual carriageway at the right junction. No amount of poor navigation skill could have led you to fail that many times. You should have realised, then, that the place distorted reality around it. Whether it was just unusually massive, or unusually evil, you couldn’t tell from the outside. All you could tell was that it twisted your perceptions, made your mind and your car run in circles. But these circles were concentric, spiralling ever inwards, towards the core. Once you saw the sign and the inviting arrow beside that junction, all hope was already lost. You were caught in its net.

As General Adama would say, “Frak”.

Frak, 5,99 Euros.

Frak, 5,99 Euros.

From the moment you step inside the door, pick up your eye-wateringly yellow bag and utterly useless paper tape measure, it has you. You will follow the arrows on the floor, never deviating from the predetermined path that your Swedish overlords have ordained for you. There are shortcuts, sure, but do you really want to try them? The other customers will give you strange looks, they’ll know that you’re not yet truly one of them. And they will report it to a member of staff, as is the duty of a Loyal Customer. Then you will be dealt with. No, no, dear customer, it is better to stay on the path.

Heed the throng of Loyal Customers. Their bellies are full of nourishing meatballs, and they have set off on the Great Pilgrimage with you. Their children scream and wail while they peruse the bland infinity of moderately-priced flat-pack furniture, but to no avail. The adults are consumed, they have become cogs in the machine, and you are elated to be joining them.

The names, the names are what seals it. The twisted, maddening names, the names that perhaps once were Swedish or some other language before the Taint reached them. Now they are trapped in a Limbo between meaning and non-meaning, luring you in, trying to get you to understand them. You look, you try to pronounce them, you curl the sounds around your tongue, probing for meaning, but there is none. They will haunt you for the rest of your days, sitting in the back of your mind, luring you back to this place just in case you can extract some meaning from a second exposure. Behold the names, behold their terrible glory! Behold the creature of madness that spawned them! Chant with me! Ia! Ia! Cthulhu f’thagn!

Behold also the Stack of Identical Grinning Babies!

Behold also the Stack of Identical Grinning Babies!

Beware most of all what seems to be the end of your journey, for there is a terrible choice that awaits you. There are steps up and steps down. Those leading up are warm and inviting, ushering you on with a yellow tone you now find soothing to your soul. But beware it, beware it! It leads back to the entrance again, from where you have no choice but to complete your whole damning journey again, hoping and praying that you will still have enough sanity left to choose differently next time. If not, all hope is lost. You will follow the Path again and again, forevermore walking the spacious showrooms of this cursed place. One day you will awaken from where you had collapsed on a comfortable pine-effect divan and find yourself changed, wearing a yellow polo shirt and with a spacious utility belt for pencils and tape measures. You will have become an employee.

No, such things should not be mentioned. It is too terrible a fate. Take heed of my warning, Loyal Customer, and choose the steps going down. They lead into the belly of the beast, a grey expanse of unending shelves where boxes are born and die. People here have discarded their yellow bags in favour of metal trolleys, all the better to gorge themselves on the wares of this place.

This is the most dangerous place of all, but you must endure it. Your life depends on reaching the end of it. It is guarded by the beeping, clacking checkouts and the fallen employees who feed them, but get up to speed on the trolleys and you just might make it through.

'Salida' might be in some kind of crazy Paella-language, but at least it's a real word.

'Salida' might be in some kind of crazy Paella-language, but at least it's a real word.

Take heart, dear Loyal Customer. Escape is possible, but you must persevere. Here I have told you everything I know, everything I have experienced, in the hope that it will aid you. I ask of you, if you should make it out alive with this document, place it as near to the entrance as you dare venture in the hope that some other poor soul will find it and survive just as you have.

Farewell, and good luck.

Yours in faith,

Sultan Hamnvik

Lord of Mesopotamia

Part-time Viking Hamster

Sultan Hamnvik

An Ode to Sharepoint

At a loss for other, more pleasant subjects to blog about, I will instead write about my nemesis, that being that has brought naught but pain to my life. I speak, of course, of Microsoft Sharepoint.

To upgrade one’s version of Windows — Vista to 7, say — is by and large a pretty painless experience for the home user. Office, likewise — there’s no dread that your Office 2003 files will be completely unopenable in Office 2007. So why is the poor sysadmin not afforded the same easy upgrade path?

In order to move an existing SharePoint Services 2 website to a new network with Microsoft Office Sharepoint Services 2007, one must:

  1. Learn more than is healthy about the workings of Sharepoint and IIS (2 days, d10 SAN)
  2. Back up the original site to disk (using stsadm.exe not smigrate.exe, as the latter is broken) (5 hours, 13 GB)
  3. Install Windows Server, IIS, SQL Server and Sharepoint Services 2 on a new machine (1 hour)
  4. Configure said IIS, SQL and Sharepoint (1 hour)
  5. Restore the Sharepoint site from disk onto the new machine (>8 hours, >120 GB, d10 SAN, fails unrecoverably when out of disk space)
  6. Perform an in-place upgrade to Sharepoint Services 3 (Several hours, 40 GB, may fail unrecoverably)
  7. Back up this site to disk (5 hours, 15 GB)
  8. Configure MOSS 2007 on the destination server (2 hours, 24 Google searches, d10 SAN)
  9. Restore the disk backup to the MOSS 2007 server (5 hours, 40 GB, may fail right at the end if previous step performed incorrectly, d100 SAN if this occurs).
  10. Manually recreate permissions on every Sharepoint site since all the users are now part of a new domain (8 hours, d10 SAN)
  11. Perform a ritual to offer Great Cthulhu the souls of Microsoft’s Sharepoint development team (d30 SAN, remarkably quick by comparison)

I began this task on Tuesday afternoon as a mildly knowledgeable Sharepoint user with virtually no admin experience. By Thursday afternoon, I may have been our company’s most experienced Sharepoint-wrangler. On Friday morning, I started the above procedure. We are now on Step 5. 200 people are expecting to have Sharepoint access tomorrow. They have not a snowball’s chance in R’yleh.