- Right-click on the desktop and choose
New > Shortcut. - Type
shutdown.exe -s -t 00in the location box and pressNext. - Type
Turn off computeras the name of the shortcut and then pressFinish. - Right-click the new icon that has appeared on the desktop and select
Properties. - Click the
Change Icon...button on theShortcuttab. - Type
%SystemRoot%\system32\SHELL32.dllin the location box and pick the Shutdown icon, which looks like a red square containing a circle with a vertical line.
Monday, December 28, 2009
Add Shutdown Icon to Desktop
Today, I added a shutdown icon to my Dad's Windows XP desktop, to make it easier for him to turn off the computer. This is how you can do it:
Adding a JProgressBar to a JTable Cell
Create a cell
TableCellRenderer which uses a JProgressBar as follows:
import java.awt.Component;
import javax.swing.JProgressBar;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
public class ProgressCellRenderer extends JProgressBar
implements TableCellRenderer {
/**
* Creates a JProgressBar with the range 0,100.
*/
public ProgressCellRenderer(){
super(0, 100);
setValue(0);
setString("0%");
setStringPainted(true);
}
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
//value is a percentage e.g. 95%
final String sValue = value.toString();
int index = sValue.indexOf('%');
if (index != -1) {
int p = 0;
try{
p = Integer.parseInt(sValue.substring(0, index));
}
catch(NumberFormatException e){
}
setValue(p);
setString(sValue);
}
return this;
}
}
Apply the cell renderer to a specific column in the table:
JTable myTable = new JTable(); TableColumn myCol = myTable.getColumnModel().getColumn(1); myCol.setCellRenderer(new ProgressCellRenderer());Now whenever you update a value in that column, the JProgressBar will get updated accordingly.
Labels:
Java,
programming,
swing
Sunday, December 27, 2009
Using Hermes to Browse WebLogic Topics/Queues
Hermes is a useful tool which allows you to browse JMS topics and queues. I use WebLogic as my JMS provider and it was not trivial trying to connect to my topic using Hermes, so I thought I'd post instructions to help others trying to do the same.
Here are the steps you need to take, in order to browse WebLogic queues and topics using Hermes:
1. Install HermesJMS
- Download Hermes from here.
- It comes as an installer jar file which you can run using the command:
java -jar hermes-installer-1.13.jar. - Once installed, start it using
hermes.bat.
- On the menubar go to
Actions > New > New session...to open thePreferencesdialog. - Click on the
Providerstab. - Right-click to
Add Groupand call it "weblogic92", for example. - Right-click on
LibrarytoAdd JAR(s)and select your weblogic jar file from the file chooser dialog. - Select
Don't Scanwhen prompted to scan the jar file. - Click
Applyand close the dialog.
- On the menubar go to
Actions > New > New session...to open thePreferencesdialog. - Click on the
Sessionstab. - Type a name for the session. For example, "myweblogic".
- In the
Plug Inlist selectBEA WebLogic. - Under
Connection Factoryclass, pickhermes.JNDITopicConnectionFactory. - Select
weblogic92(defined in step 2) from theLoaderdropdown. - Add property:
initialContextFactorywith a value ofweblogic.jndi.WLInitialContextFactory. - Add property:
providerURLwith a value of your URL e.g. t3://myhost:2120. - Add property:
bindingwith a value of the name of your connection factory e.g. myConnectionFactory. - Add any other properties you may have e.g. securityCredentials etc.
- Remove all
Destinationsby right-clicking and selectingRemove. - Press
OK.
- On the left navigation tree, go into
jms > sessions > myweblogic. - Right-click "myweblogic" (the new session created in step 3), and click
Discover. You will see a list of queues and topics appear. - Click on any one of them to browse.
Labels:
hermes,
Java,
JMS,
programming,
weblogic
Friday, December 25, 2009
Generics and Class.forName
This post shows how you can create objects of a specified class,
using a class name and the supertype of the class you are trying to create.
public final class BeanCreator {
/**
* Suppress constructor.
*/
private BeanCreator(){
}
/**
* Creates an object of the class name and supertype.
* @param <T>
* @param className
* @param superType
* @return
* @throws ClassNotFoundException
*/
public static <T> T create(final String className,
final Class<T> superType) throws Exception {
final Class< ? extends T> clazz =
Class.forName(className).asSubclass(superType);
return create(clazz);
}
/**
* Creates an object of the specified class using
* its public or private no-arg constructor.
*
* @param <T>
* @param classToCreate
* @return
*/
public static <T> T create(final Class<T> classToCreate)
throws Exception {
final Constructor<T> constructor =
classToCreate.getDeclaredConstructor();
if (constructor == null) {
throw new Exception("Could not create a new "+
"instance of the dest object: " + classToCreate
+ ". Could not find a no-arg constructor.");
}
// If private, make it accessible
if (!constructor.isAccessible()) {
constructor.setAccessible(true);
}
return constructor.newInstance();
}
}
Labels:
Java,
programming
Subscribe to:
Comments (Atom)