Java Reference
In-Depth Information
public
public static
void setSystemClipboardContents ( Component c , String srcData ) {
iif ( srcData != null
static void
null ) {
Clipboard clipboard = c . getToolkit (). getSystemClipboard ();
StringSelection contents = new
new StringSelection ( srcData );
clipboard . setContents ( contents , new
new ClipboardOwner () {
public
public void
void lostOwnership ( Clipboard clipboard ,
Transferable contents ) {
// don't care
}
});
}
}
/** Print a yes/no prompt; return true if the user presses yes
*/
public
public static
static boolean
boolean confirm ( JFrame parent , String message ) {
int
int confirm = JOptionPane . showConfirmDialog ( parent , message , "Confirm" ,
JOptionPane . YES_NO_OPTION ,
JOptionPane . QUESTION_MESSAGE );
// Only selecting Yes choice will result in true
return
return confirm == 0 ;
}
/** Save the X and Y locations in Preferences node provided.
*/
public
public static
static void
void setSavedLocation (
final
final Preferences pNode , final
final Window w ) {
Point where = w . getLocation ();
int
int x = ( int
int ) where . getX ();
pNode . putInt ( "mainwindow.x" , Math . max ( 0 , x ));
int
int y = ( int
int ) where . getY ();
pNode . putInt ( "mainwindow.y" , Math . max ( 0 , y ));
}
/** Retrieve the saved X and Y from Preferences
*/
public
public static
static Point getSavedLocation ( final
final Preferences pNode ) {
int
int savedX = pNode . getInt ( "mainwindow.x" , - 1 );
int
int savedY = pNode . getInt ( "mainwindow.y" , - 1 );
return
return new
new Point ( savedX , savedY );
}
/**
* Track a Window's position across application restarts; location is saved
Search WWH ::




Custom Search