Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

satya sahu

Ranch Hand
+ Follow
since Mar 26, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by satya sahu

Hi All,
The JVM is crashing giving the following error.
I have gone through the sites, everybody have mentioned the problem but no proper solution.
Can somebody guide me in this.

Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x80D8355
Function=JVM_RegisterUnsafeMethods+0x12A8
Library=D:\E(z)RF Application Suite\WebNMS\jre\bin\client\jvm.dll

Current Java thread:
at java.lang.Throwable.fillInStackTrace(Native Method)
- locked <0x1345b688> (a java.lang.NullPointerException)
at java.lang.Throwable.<init>(Unknown Source)
at java.lang.Exception.<init>(Unknown Source)
at java.lang.RuntimeException.<init>(Unknown Source)
at java.lang.NullPointerException.<init>(Unknown Source)
[error occured during error reporting]


PC configuration:
java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)

Windows Server 2003, service pack 2, 3.06 GHz processor speed and 4 GB RAM.



Thanks in advance.

Regards,
Satya
9 years ago
Hi,
After running my java application for around 10-12 hours i am getting the following error and finally the server stops.
Error: "java.lang.OutOfMemoryError: unable to create new native thread"
System configuration:
1. Java : j2sdk1.4.2_08
2. System configruation: Windows XP service pack 3, (2x3.0Ghz with 4 GB RAM)
3. I run my application as Java Services and the java services has the "-Xmx512m", no other JVM args settings.

Can somebody help me in knowing the cause of the problem and suggest me the best solution.

Regards,
Satya
9 years ago
HI all,
I have to take some backup of some files from my application using java program. The final output should be in .tar format because this backed up data will be used in the application running in linux box and the linux box due to limited space does not have any other utilities like GZIP or unzip. Only the tar is supported. Hence i need to produce the back up data in tar format.
Please advice me how to do it in windows environment ?
Sample code will be really great help for me.

Thanks in advance.
Satya
10 years ago
Hi,
I have two for loops,
for(int i = 0; i < 10000, i++)
and
for(int i = 10000, i>=0; i--)
Which one is faster and why?
This was asked to me in some interview, and i could not answer.
I searched through the Net, but not getting any answer.
Can anybody help me to understand the correct answer of this.
Thanks in advance.
10 years ago
What is the time complexity of insertion,search and deletation operation of
a) HashMap
b) HashTable
c) TreeMap
d)Vector
e)ArrayList
and which is better to use in what scinario.
10 years ago
What is the difference between validate(), invalidate() and revalidate() methods, and when to use them.
Also i am getting able to understand difference between paint() and repaint().
When to use the updateUI() method.

Please explain it with some example.

Thanks in advance.
10 years ago
Can an anonymous class be declared as implementing an interface and extending a class?
The Answer is :An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

My question is why can't i declare both?
10 years ago
Can there be an abstract class with no abstract methods in it?
If the answer is yes, then what is the use of such class?
10 years ago
The code suggested,i am already doing that. After reloading the image, it is expected to take the new size(height and width) of the image, but it still takes the old size. I have put prints in the paint and i have confirmed this.
It still prints the old sizes. Only if i close the application and restart it again, it will print the new size.

It is failing thats why i am asking for the solution.
10 years ago
Actually the resizing of the image is done for some particular purpose which is done externally, may be using the MS paint. In the application the same image with its previous size is displayed. I know its size is changed. So i browse to the same path and load the same resized image.
The code executed is
ImageIcon icon = new ImageIcon(selectedFile.getAbsolutePath());
mapPanel.repaint();
In paintComponet(Graphics g2D){
imageWidth = icon.getIconWidth();
imageHeight = icon.getIconHeight();
g2D.drawImage(icon.getImage(), 0, 0, (int)imageWidth, (int)imageHeight, this);
}
The paintComponent uses the image's height and width to paint it. And here this fails to get the changed size. It paints the initial size. If i close the application and runs it again, it loads the new sized image. But reopening the client is not a solution.
So how do i solve it ?
10 years ago
Yes, i will take care of this from next time.
But please help me to get the solution.
10 years ago
The code only formated. But this does not solve my problem.
10 years ago
Hi,
In my application using the browse button i load the image.
I am creating an instance of ImageIcon by giving the above specific path in the constructor.

"ImageIcon icon1 = new ImageIcon(selectedFile.getAbsolutePath()); "

Then i use this icon instance to paint in a JPanel embeded in the scrollpane.
In the paintComponent method of JPanel I get the width, height of the image icon and set the preferred size
of the panel to display the full image.

Now because of some specific requirement in the project i resize(enlarged/reduce) the same image and try to reload the image through the browse button.
And this resized image should be painted in the JPanel.

How to resize the image : Open in paint and enlarge or reduce the size of the image.


But the image size does not changes in the panel.

But if i close the application and run it again, then the new height & width is taken.

I have gone through the constructor of ImageIcon, it says in the loadImage() method media trakcer already
loaded the image.
I think because of this it is not taking the new resized image.

Can anybody give me a solution to this problem.

I am attaching sample code for this.
Need not to go through the initComponents() method, as it is auto generated code from netbeans.





import java.awt.image.BufferedImage;
import javax.swing.JFileChooser;
import java.applet.*;
import java.io.File;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.filechooser.FileFilter;

public class ImageSizeCheckFrame extends javax.swing.JFrame {
File selectedFile ;
int counter = 0;
ImageIcon icon;
/** Creates new form ImageSizeCheckFrame */
public ImageSizeCheckFrame() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
prevImgPathLBL = new javax.swing.JLabel();
prevImgWidthLBL = new javax.swing.JLabel();
prevImgHeightLBL = new javax.swing.JLabel();
currImgPathLBL = new javax.swing.JLabel();
currImgWidthLBL = new javax.swing.JLabel();
currImgHeightLBL = new javax.swing.JLabel();
prevImgPathTXT = new javax.swing.JTextField();
prevImgWidthTXT = new javax.swing.JTextField();
prevImgHeightTXT = new javax.swing.JTextField();
currImgPathTXT = new javax.swing.JTextField();
currImgWidthTXT = new javax.swing.JTextField();
currImgHeightTXT = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("Browse");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setText("Calculate");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

prevImgPathLBL.setText("Previous Image path:");

prevImgWidthLBL.setText("Previous Iamge width:");

prevImgHeightLBL.setText("Previous Image height:");

currImgPathLBL.setText("Current Image path:");

currImgWidthLBL.setText("Current Iamge width:");

currImgHeightLBL.setText("Current Image height:");

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(48, 48, 48)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jButton2)
.add(layout.createSequentialGroup()
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 147, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(27, 27, 27)
.add(jButton1))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(prevImgPathLBL)
.add(prevImgWidthLBL)
.add(prevImgHeightLBL)
.add(currImgPathLBL)
.add(currImgWidthLBL)
.add(currImgHeightLBL))
.add(30, 30, 30)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(prevImgWidthTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(prevImgPathTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(prevImgHeightTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(currImgPathTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(currImgWidthTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(currImgHeightTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createSequentialGroup()
.add(jButton2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(prevImgPathLBL))
.add(prevImgPathTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(prevImgWidthLBL)
.add(prevImgWidthTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(7, 7, 7)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(prevImgHeightLBL)
.add(prevImgHeightTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(49, 49, 49)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(currImgPathLBL)
.add(currImgPathTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(currImgWidthLBL)
.add(currImgWidthTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(7, 7, 7)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(currImgHeightLBL)
.add(currImgHeightTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(47, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(counter > 0){
prevImgPathTXT.setText(selectedFile.getAbsolutePath());
icon = new ImageIcon(selectedFile.getAbsolutePath());
prevImgWidthTXT.setText(icon.getIconWidth()+"");
prevImgHeightTXT.setText(icon.getIconHeight()+"");
}
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setAcceptAllFileFilterUsed(false);
ImageFileFilter filter = new ImageFileFilter();
fileChooser.addChoosableFileFilter(filter);
int retVal = fileChooser.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
jTextField1.setText(fileChooser.getSelectedFile().getAbsolutePath());
selectedFile = fileChooser.getSelectedFile();
}
counter++;
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
currImgPathTXT.setText(selectedFile.getAbsolutePath());

ImageIcon icon1 = new ImageIcon(selectedFile.getAbsolutePath());

currImgWidthTXT.setText(icon1.getIconWidth()+"");
currImgHeightTXT.setText(icon1.getIconHeight()+"");
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
ImageSizeCheckFrame obj = new ImageSizeCheckFrame();
obj.setSize(700, 400);
obj.setVisible(true);

}
});
}

// Variables declaration - do not modify
private javax.swing.JLabel currImgHeightLBL;
private javax.swing.JTextField currImgHeightTXT;
private javax.swing.JLabel currImgPathLBL;
private javax.swing.JTextField currImgPathTXT;
private javax.swing.JLabel currImgWidthLBL;
private javax.swing.JTextField currImgWidthTXT;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel prevImgHeightLBL;
private javax.swing.JTextField prevImgHeightTXT;
private javax.swing.JLabel prevImgPathLBL;
private javax.swing.JTextField prevImgPathTXT;
private javax.swing.JLabel prevImgWidthLBL;
private javax.swing.JTextField prevImgWidthTXT;
// End of variables declaration

}


class ImageFileFilter extends FileFilter{
private String description = "*.gif,*.jpg,*.png,*.jpeg";
private ArrayList list = new ArrayList();
{
list.add(".gif");
list.add(".jpg");
// anurag start
// don't show bmp files for selection
//list.add(".bmp");
list.add(".jpeg");
list.add(".png");
//list.add(".JPG");
//list.add(".JPEG");
// anurag end
}
public String getDescription(){
return description;
}

public boolean accept(File file){
if(file.isDirectory()) return true;
String fileName = file.getName().toLowerCase();
for(int i=0;i<list.size();i++){
String n = (String)list.get(i);
if(fileName.endsWith(n)) return true;
}
return false;
}
}
10 years ago
Hi,
In my application using the browse button i load the image.
I am creating an instance of ImageIcon by giving the above specific path in the constructor.

"ImageIcon icon1 = new ImageIcon(selectedFile.getAbsolutePath()); "

Then i use this icon instance to paint in a JPanel embeded in the scrollpane.
In the paintComponent method of JPanel I get the width, height of the image icon and set the preferred size
of the panel to display the full image.

Now because of some specific requirement in the project i resize(enlarged/reduce) the same image and try to reload the image through the browse button.
And this resized image should be painted in the JPanel.

How to resize the image : Open in paint and enlarge or reduce the size of the image.


But the image size does not changes in the panel.

But if i close the application and run it again, then the new height & width is taken.

I have gone through the constructor of ImageIcon, it says in the loadImage() method media trakcer already
loaded the image.
I think because of this it is not taking the new resized image.

Can anybody give me a solution to this problem.

I am attaching sample code for this.






import java.awt.image.BufferedImage;
import javax.swing.JFileChooser;
import java.applet.*;
import java.io.File;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.filechooser.FileFilter;

public class ImageSizeCheckFrame extends javax.swing.JFrame {
File selectedFile ;
int counter = 0;
ImageIcon icon;
/** Creates new form ImageSizeCheckFrame */
public ImageSizeCheckFrame() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
prevImgPathLBL = new javax.swing.JLabel();
prevImgWidthLBL = new javax.swing.JLabel();
prevImgHeightLBL = new javax.swing.JLabel();
currImgPathLBL = new javax.swing.JLabel();
currImgWidthLBL = new javax.swing.JLabel();
currImgHeightLBL = new javax.swing.JLabel();
prevImgPathTXT = new javax.swing.JTextField();
prevImgWidthTXT = new javax.swing.JTextField();
prevImgHeightTXT = new javax.swing.JTextField();
currImgPathTXT = new javax.swing.JTextField();
currImgWidthTXT = new javax.swing.JTextField();
currImgHeightTXT = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("Browse");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setText("Calculate");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

prevImgPathLBL.setText("Previous Image path:");

prevImgWidthLBL.setText("Previous Iamge width:");

prevImgHeightLBL.setText("Previous Image height:");

currImgPathLBL.setText("Current Image path:");

currImgWidthLBL.setText("Current Iamge width:");

currImgHeightLBL.setText("Current Image height:");

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(48, 48, 48)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jButton2)
.add(layout.createSequentialGroup()
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 147, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(27, 27, 27)
.add(jButton1))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(prevImgPathLBL)
.add(prevImgWidthLBL)
.add(prevImgHeightLBL)
.add(currImgPathLBL)
.add(currImgWidthLBL)
.add(currImgHeightLBL))
.add(30, 30, 30)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(prevImgWidthTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(prevImgPathTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(prevImgHeightTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(currImgPathTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(currImgWidthTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
.add(currImgHeightTXT, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createSequentialGroup()
.add(jButton2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(prevImgPathLBL))
.add(prevImgPathTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(prevImgWidthLBL)
.add(prevImgWidthTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(7, 7, 7)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(prevImgHeightLBL)
.add(prevImgHeightTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(49, 49, 49)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(currImgPathLBL)
.add(currImgPathTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(currImgWidthLBL)
.add(currImgWidthTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(7, 7, 7)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(currImgHeightLBL)
.add(currImgHeightTXT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(47, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(counter > 0){
prevImgPathTXT.setText(selectedFile.getAbsolutePath());
icon = new ImageIcon(selectedFile.getAbsolutePath());
prevImgWidthTXT.setText(icon.getIconWidth()+"");
prevImgHeightTXT.setText(icon.getIconHeight()+"");
}
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setAcceptAllFileFilterUsed(false);
ImageFileFilter filter = new ImageFileFilter();
fileChooser.addChoosableFileFilter(filter);
int retVal = fileChooser.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
jTextField1.setText(fileChooser.getSelectedFile().getAbsolutePath());
selectedFile = fileChooser.getSelectedFile();
}
counter++;
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
currImgPathTXT.setText(selectedFile.getAbsolutePath());

ImageIcon icon1 = new ImageIcon(selectedFile.getAbsolutePath());

currImgWidthTXT.setText(icon1.getIconWidth()+"");
currImgHeightTXT.setText(icon1.getIconHeight()+"");
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
ImageSizeCheckFrame obj = new ImageSizeCheckFrame();
obj.setSize(700, 400);
obj.setVisible(true);

}
});
}

// Variables declaration - do not modify
private javax.swing.JLabel currImgHeightLBL;
private javax.swing.JTextField currImgHeightTXT;
private javax.swing.JLabel currImgPathLBL;
private javax.swing.JTextField currImgPathTXT;
private javax.swing.JLabel currImgWidthLBL;
private javax.swing.JTextField currImgWidthTXT;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel prevImgHeightLBL;
private javax.swing.JTextField prevImgHeightTXT;
private javax.swing.JLabel prevImgPathLBL;
private javax.swing.JTextField prevImgPathTXT;
private javax.swing.JLabel prevImgWidthLBL;
private javax.swing.JTextField prevImgWidthTXT;
// End of variables declaration

}


class ImageFileFilter extends FileFilter{
private String description = "*.gif,*.jpg,*.png,*.jpeg";
private ArrayList list = new ArrayList();
{
list.add(".gif");
list.add(".jpg");
// anurag start
// don't show bmp files for selection
//list.add(".bmp");
list.add(".jpeg");
list.add(".png");
//list.add(".JPG");
//list.add(".JPEG");
// anurag end
}
public String getDescription(){
return description;
}

public boolean accept(File file){
if(file.isDirectory()) return true;
String fileName = file.getName().toLowerCase();
for(int i=0;i<list.size();i++){
String n = (String)list.get(i);
if(fileName.endsWith(n)) return true;
}
return false;
}
}
10 years ago
Hi,
In JOptionPane, I want to show password label and its corresponding password textfiled in one line and then confirm password label and corresponding textfield in another line. Can anybody give me sample code for this ??

I am able to put the controllers in the JOptionPane one below the other. But not one after the other.


private ButtonGroup buttonGroup = new ButtonGroup();
private JRadioButton radioButton1 = new JRadioButton("Use default password");
private JRadioButton radioButton2 = new JRadioButton("I have changed the password");
private JLabel passwordLbl = new JLabel("Password:");
private JTextField passwordTF = new JTextField();

private Object[] pwdArray = {passwordLbl, passwordTF};

private String difficultyString = "<html>Log in to the database failed.<br>Please select any of the following options below.</br></html>";
private Object[] radioButtonArray = {difficultyString, radioButton1, radioButton2, pwdArray};

JOptionPane.showConfirmDialog(this,
radioButtonArray, "Level selection",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE);

Please suggest me some way to achieve this.

Regards,
Satya
10 years ago