The colourful and liberal Mr Justice Michael Hartmann marked his retirement with a hint of humour in his farewell sitting yesterday as the courtroom overflowed with well-wishers.

After 21 years with the judiciary, Hartmann (pictured), who is turning 68, will step down as a full-time judge on July 23. In his next role, he will promote cross-border co-operation in legal matters.

But he will remain as a non-permanent judge at the top court, occasionally hearing some of the toughest cases.

In his speech yesterday, Hartmann said he was lucky to have been given the chance to serve as a judge in family and public law.

'[A] life in the courts, especially as a trial judge, plunges you daily into an embrace with every aspect of human fortitude and frailty,' Hartmann said.

He saved his best quips for the final part of his speech when he thanked his family and colleagues.

'They say that a retired husband often becomes a wife's full-time job,' Hartmann said. 'That will not happen to Melanie. I have always been her full-time job.'

And for his colleagues: 'Without that camaraderie, fortified by 20 years of tennis, morning coffee sessions and curry lunches, my career as a judge would have been a lot more lonely and a lot more hazardous.'

Judges and lawyers packed the courtroom, spilling outside the door, to bid farewell to the witty and compassionate Hartmann, who has been lauded for making a huge contribution to Hong Kong's judiciary.

In the course of his career, Hartmann has presided over a number of landmark and controversial cases.

For instance, he ruled that certain sections of the Crimes Ordinance were unconstitutional because they discriminated against homosexuals.

In 2008, citing procedural unfairness, he quashed a fine levied against Mike Rowse, the director general of InvestHK at the time, for the agency's failure to scrutinise the budget of HarbourFest in 2003.

Hartmann also dealt with a large number of right-of-abode cases involving children born on the mainland to Hong Kong parents.

Born in 1944 in the Indian city of Mumbai, Hartmann spent his early years in Australia before moving to Britain, and then to Zimbabwe in 1963.

The roots of his sense of humour could be found in his colourful background. While aspiring to become an advertising executive, Hartmann began his career as a journalist with a Sunday newspaper in Zimbabwe, then known as Rhodesia, before he studied law a year later.

He subsequently served as an infantry officer in Rhodesia.

Speaking of his seven years spent adjudicating judicial reviews, Hartmann said: 'Quite how I came to be given the responsibility still escapes me. [Was I] the right man in the right place at the right time? More likely, [I was] the only man in the right place at the right time.

'What matters is that serendipity presented me with the opportunity to play some small role in fashioning how our constitution was to be understood and through that, in some small measure, to play a role in seeking the betterment of this vigorous, entirely admirable society in which we live.'

Andrew Cheung Kui-nung, chief judge of the High Court, said Hartmann's judicial work had been prolific. 'His judgments were promptly delivered and were of the highest standard,' Cheung said.

Justice Secretary Wong Yan-lung also praised Hartmann for his excellent work as a jurist, saying the judge had safeguarded justice and the proper administration of the city's law.