All posts tagged with 'Code Snippets'

How to get UIDefaults in Java

06-Sep-10

If you’re loocking for Javas UIDefaults, use the UIManager class. This snippet gives you all installed UIDefaults: UIDefaults defaults = UIManager.getDefaults(); for(Enumeration e = defaults.keys(); e.hasMoreElements(); ){ String key = e.nextElement().toString(); System.out.println(key + " = " + defaults.get(key)); }UIDefaults defaults = UIManager.getDefaults(); for(Enumeration e = defaults.keys(); e.hasMoreElements(); ){ String key = e.nextElement().toString(); System.out.println(key + " […]

Read the complete article »

J2SE: Cut/Copy/Paste Helper

09-Jul-10

You wouldn’t think that having a standard edit menü with Cut, Copy and Paste buttons would be much of a problem in the J2SE world, especially regarding the fact that most standard Swing components have TransferHandlers that support the 3 operations with the standard keyboard shortcuts. First try was to user TransferHandler.getCopyAction() etc. and create […]

Read the complete article »

Oracle: Drop table if exists replacement

16-Feb-10

Mysql has a nice “if exists” addition to the drop table statement. If the table to be dropped does not exists, it doesn’t raise an exception but only creates a warning. In Oracle RDMBS you can emulate this behavior like so: BEGIN EXECUTE immediate ‘drop table INSERT_TABLE_NAME_HERE’; EXCEPTION WHEN others THEN IF SQLCODE != -942 […]

Read the complete article »

An iterable array

12-Jan-10

Java has the nice Iterable interface (since Java 5, i guess) that allows object oriented loops like List<String> strings = new ArrayList<String>(); for(String string : strings) System.out.println(string);List<String> strings = new ArrayList<String>(); for(String string : strings) System.out.println(string); but guess what, a simple array is not iterable… In case you need one, feel free to use this […]

Read the complete article »

Today: Fun with Unicode, Regex and Java.

03-Nov-09

Some would say, i have 3 problems 😉 private final static Pattern placeholder = Pattern.compile("#\\{(\\w+?)\\}");private final static Pattern placeholder = Pattern.compile("#\\{(\\w+?)\\}"); won’t match “Mot#{ö}rhead” for example. To replace the word character \w you either need the list of possible unicodeblocks like [\p{InLatin}|\p{InEtc}] (you get the codes for the blocks through “Character.UnicodeBlock.forName” or you’re lazy like […]

Read the complete article »