Example source code for GridLayout
Tip for GridLayout
GridLayout will arrange components into container from left to right like FlowLayout do. But what make it different to FlowLayout ? The answer is, it will arrange components in grid. See the image below. It represent a grid with 3 rows and 2 columns. First component will be put into first row and first column. Second component will be put into first row and second column. Third component will be put into second row and first column. Fourth component will be put into second row and second column. Fifth component will be put into third row and first column and last component will be put into third row and second column.
Example source code for GridLayout
Example source code for GridLayout
Tip for BorderLayout
BorderLayout is also a layout manager like FlowLayout. But, it not arrange components in container from left to right like FlowLayout do. It will arrange component in five part.
NORTH
SOUTH
CENTER
EAST
WEST
Example source code for BorderLayout
NORTH
SOUTH
CENTER
EAST
WEST
Example source code for BorderLayout
Tip for FlowLayout
FlowLayout is use to arrange components in a container from left to right. If it reached at the end of the container, but there are still left other component, it will go to the next line in the container and start again arrange component from left to right.
Example of container : JFrame, JPanel, JWindow, JInternalFrame
(Use to hold other component)
Example of component : JPanel, JButton, JTextField, JCheckBox, JRadioButton
Example source code for FlowLayout
Example of container : JFrame, JPanel, JWindow, JInternalFrame
(Use to hold other component)
Example of component : JPanel, JButton, JTextField, JCheckBox, JRadioButton
Example source code for FlowLayout
Set JTextField background image
Complete source code below will show you, how to set image background in a JTextField. You can download image (textFieldBackgroundImage.jpg) that use in source code at below.
*******************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldBackgroundImage.java
*******************************************************************
*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************
*******************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldBackgroundImage.java
*******************************************************************
import javax.swing.*;
import java.awt.*;
public class SetJTextFieldBackgroundImage extends JTextField
{
public SetJTextFieldBackgroundImage()
{
JFrame frame=new JFrame("Set JTextField background image");
frame.add(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,65);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
}
public void paint(Graphics g)
{
setOpaque(false);
//Image that will be set as JTextField background
//I suggest, image that will be use is blur...
//If image is locate at other location, you must put it's full location address.
//For example : C:\\Documents and Settings\\evergreen\\Desktop\\textFieldBackgroundImage.jpg
ImageIcon ii=new ImageIcon("textFieldBackgroundImage.jpg");
Image i=ii.getImage();
g.drawImage(i,0,0,this);
super.paint(g);
}
public static void main(String[]args)
{
SetJTextFieldBackgroundImage sjtfbi=new SetJTextFieldBackgroundImage();
}
}
*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************
textFieldBackgroundImage.jpg
Determine character is whitespace
Complete source code below will show you, how to determine character is whitespace or not in java.
*******************************************************************
COMPLETE SOURCE CODE FOR : DetermineCharacterIsSpace.java
*******************************************************************
*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************
*******************************************************************
COMPLETE SOURCE CODE FOR : DetermineCharacterIsSpace.java
*******************************************************************
public class DetermineCharacterIsSpace
{
public static void main(String[]args)
{
//Create a space character using char by press spacebar once between single quote(' ')
//You can try change it's value by change it to a letter 'A' for example.
char a=' ';
//Determine created character is space or not
//using method isWhitespace from class Character.
//isWhitespace is a static method, so we don't need to create object when
//we want to use it.
if(Character.isWhitespace(a))
{
//Print (It is a whitespace) if character is a whitespace
System.out.println("It is a whitespace");
}
else
{
//Print (It is not a whitespace) if character is not a whitespace
System.out.println("It is not a whitespace");
}
}
}
*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************
Subscribe to:
Posts (Atom)