Create exception handling
Java exception handling
Java modal window
Java validate integer user input
Java determine drive pathname
Java and pathname
Before i go through about file's operation, i want to share with you about "pathname" keyword. In java there has lot of methods play with pathname.
For example :
When we want to create a file instance like below
******************************************
File myFile=new File("c:\\mytext.txt");
******************************************
"c:\\mytext.txt" is a pathname for mytext.txt that locate in c drive.Origin for c:\\mytext.txt is c:\mytext.txt.We use two backslash to prevent syntax error when we compile it.
So, what is pathname ?
For example :
When we want to create a file instance like below
******************************************
File myFile=new File("c:\\mytext.txt");
******************************************
"c:\\mytext.txt" is a pathname for mytext.txt that locate in c drive.Origin for c:\\mytext.txt is c:\mytext.txt.We use two backslash to prevent syntax error when we compile it.
So, what is pathname ?
- A pathname is a string that describes what directory the file is in, as well as the name of the file.
Java open cd tray in Windows XP
Call jar file from a java program
Set JTextField selection color
Complete source code below will show you how to set JTextField selection color.
***************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldSelectionColor.java
***************************************************************
***************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************
***************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldSelectionColor.java
***************************************************************
import javax.swing.*;
import java.awt.*;
public class SetJTextFieldSelectionColor
{
public static void main(String[]args)
{
JTextField jtf=new JTextField("Select this text");
//Color that will use as JTextField's selection color
//It is base on RGB value
//Red=255
//Green=0
//Blue=0
//You can use color picker at above to get RGB value
Color selectionColor=new Color(255,0,0);
//Set JTextField selection color
jtf.setSelectionColor(selectionColor);
JFrame myWindow=new JFrame("Set JTextField selection color");
myWindow.add(jtf);
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.setSize(400,50);
myWindow.setLocationRelativeTo(null);
myWindow.setVisible(true);
}
}
***************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************
Set JTextField caret color
Complete source code below will show you, how to set JTextField caret color.
****************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldCaretColor.java
****************************************************************
****************************************************************
JUST COMPILE AND EXECUTE IT
****************************************************************
****************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldCaretColor.java
****************************************************************
import javax.swing.*;
import java.awt.*;
public class SetJTextFieldCaretColor
{
public static void main(String[]args)
{
JTextField jtf=new JTextField(20);
jtf.setFont(new Font("Verdana",Font.BOLD,34));
JFrame myFrame=new JFrame("Set JTextField caret color");
//Set caret color base on RGB value
//R=255
//G=0
//B=0
//You can get RGB value from color picker at above
jtf.setCaretColor(new Color(255,0,0));
myFrame.setLayout(new FlowLayout());
myFrame.add(jtf);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.pack();
myFrame.setLocationRelativeTo(null);
myFrame.setVisible(true);
}
}
****************************************************************
JUST COMPILE AND EXECUTE IT
****************************************************************
Subscribe to:
Posts (Atom)