Table of Contents
hide
Example : How to display multiline messages on jLabel and jButton in java using Net Beans IDE 8.2 .
public UserRegistrion() {
initComponents();
jLabel2.setText("<html>Coders<br> Helpline<br>...</html>");
jButton1.setText("<html> <b><u> Coders </u></b> <br>Helpline </html>");
}
NB ; First of all create jLabel2 and jButton1 on jFrame1.
Example : How to display different type of message format/dialog window with static package in java using Net Beans IDE 8.2 .
import static javax.swing.JOptionPane.*;
public UserRegistrion() {
initComponents();
String Str= new String("Welcome to CodersHelpline");
showMessageDialog(null,Str);
----------------- OR --------------
showMessageDialog(null,"Write Message Here"); //Only OK dialog appear with title'Message'.
----------------- OR --------------
showConfirmDialog(null,"Do You want to delete!","Confirm Deletion",YES_NO_OPTION);
----------------- OR --------------
int x = showConfirmDialog(null,"Do You want to delete!","Confirm Deletion",
YES_NO_CANCEL_OPTION);
if(x== 0)
{
jTextField1.grabFocus();
}
else if(x== 1)
{
jTextField2.grabFocus();
}
else
{
jTextField3.grabFocus();
}
----------------- OR --------------
Object[] options = {"Okay","Cancel","Ask Me Later"}; // To set customize button label.
int x =showOptionDialog(null,"Would you like to save it", null, YES_NO_CANCEL_OPTION,
QUESTION_MESSAGE, null, options, options[2]);
if(x== 0)
{
jTextField1.grabFocus();
}
else if(x== 1)
{
jTextField2.grabFocus();
}
else
{
jTextField3.grabFocus();
}
}
Example : How to display different type of message format/dialog window with normal package in java using Net Beans IDE 8.2 .
import javax.swing.JOptionPane;
public UserRegistrion() {
initComponents();
String Str= new String("Codershelpline");
JOptionPane.showMessageDialog(null,Str);
----------------- OR --------------
JOptionPane.showMessageDialog(null,"Codershelpline");
----------------- OR --------------
JOptionPane.showConfirmDialog(null,"Do You want to delete!","Confirm Deletion",JOptionPane.
YES_NO_OPTION);
----------------- OR --------------
JOptionPane.showConfirmDialog(null,"Do You want to delete!","Confirm Deletion",JOptionPane.
YES_NO_CANCEL_OPTION);
----------------- OR --------------
try
{
}
Catch(Exception ex)
{
JOptionPane.showMessageDialog(null,ex); //Message for Exception Handling.
}
----------------- OR --------------
JOptionPane.showMessageDialog(null," Write Customize Display Message Here ","Title Message
Write Here",JOptionPane.WARNING_MESSAGE/PLAIN_MESSAGE/ERROR_MESSAGE/INFORMATION_MESSAGE);
//customize message.
----------------- OR --------------
int x = JOptionPane.showConfirmDialog(null,"Do You want to delete!","Confirm Deletion",
JOptionPane.YES_NO_OPTION);
//JOptionPane.showMessageDialog(null,x); // To display the value of 'x'.
if(x== 0) //for 'YES'
{
jTextField1.grabFocus();
}
else //for 'NO' where x==1.
{
jTextField2.grabFocus();
}
----------------- OR --------------
int x = JOptionPane.showConfirmDialog(null,"Do You want to delete!","Confirm Deletion",
JOptionPane.YES_NO_CANCEL_OPTION);
//JOptionPane.showMessageDialog(null,x); // To display the value of 'x'.
if(x== 0) //for 'YES'
{
jTextField1.grabFocus();
}
else if(x== 1) //for 'NO' where x==1.
{
jTextField2.grabFocus();
}
else //for 'Cancel' where x==2 and for close button(X) of confirm dialog x==-1.
{
jTextField3.grabFocus();
}
----------------- OR --------------
Object[] options = {"Okay","Cancel","Ask Me Later"}; // To set customize button label.
int x =JOptionPane.showOptionDialog(null,"Would you like to save it", null, JOptionPane.
YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
//JOptionPane.showMessageDialog(null,x); // To display the value of 'x'.
if(x== 0) //for 'Okay'
{
jTextField1.grabFocus();
}
else if(x== 1) //for 'Cancel' where x==1.
{
jTextField2.grabFocus();
}
else //for 'Ask Me Later' where x==2 and for close button(X) of confirm dialog x==-1.
{
jTextField3.grabFocus();
}
}
0 Comments