Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image disapears when releasing jSlider 1

Status
Not open for further replies.

russland

Programmer
Jan 9, 2003
315
CH
hi,

goal: resizing an image by moving the JSlider's needle.

not working: i resizing work just fine, but outputing the image to simple jPanel doesn't work properly. It resizes and displays the image as long as the the mouse button is NOT release. If done, the image disapears.

jPanelPicture.removeAll();
and
jPanelPciture.repaint();
didn't help?

any clue how this works?
cheers





public void resizeImage(){
//---Bildbearbeitung---
String file1 = "a.jpg";
RenderedImage source = JAI.create("fileload", file1);

ParameterBlock pb = new ParameterBlock();
/*pb.addSource(source);
pb.add(null).add(null).add(null).add(null).add(null);
RenderableImage ren = JAI.createRenderable("renderable", pb);

int h = source.getHeight();
int w = source.getWidth();
PlanarImage dst = (PlanarImage) ren.createScaledRendering(w, h, null);
*/
//verkleinerungsfaktor
float resizeFactor = (float)jSliderVerkleinerung.getValue() / 100;
String strPercent = String.valueOf(jSliderVerkleinerung.getValue());
jLabelSliderValue.setText(strPercent + "%");
if(resizeFactor == 0.00F)
resizeFactor = 0.01F;

//verkleinern
pb = new ParameterBlock();
pb.addSource(source);
pb.add(resizeFactor); // 0.3 is just some test data
pb.add(resizeFactor);
pb.add(0.0f);
pb.add(0.0f);
pb.add(new InterpolationNearest());// <-- this is the key
PlanarImage img = JAI.create("scale", pb, null);

DisplayJAI dj = new DisplayJAI(img);

jPanelPicture.removeAll();
jPanelPicture.add(dj);
jPanelPicture.repaint();

}
 
your should have your myJPanel extends JPanel
your method resizeImage should set the shrink or enlarge size on variable of myJPanel.
you should override the public void paint(Graphics g) of myJPanel, the paint method should read the shrink rate and
draw the final image...
 
public void resizeImage() don't have to draw image, it just set the shrink or enlarge rate and call myJPanel repaint();
Let myJPanel transform and draw the image.
 
hi, I also found this method to check. for some reason the slider fires 4x when slider is moved. the getValueIsAdjusting() reduces it to 1x.

if (!slider.getValueIsAdjusting()) {
System.out.println("moved slider");
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top