Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JInternalFrames + JSliders  RSS feed

 
Marie Henry
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently working on an application that uses JInternalFrames with JSliders. However, when I try to move a slider on an unselected frame by clicking and dragging it, it only selects the frame and then I must click again to use the slider.
To check this behavior I took some simple JInternalFrame code off the java.sun site and added JSliders to two InternalFrames. The code is included below. To witness this behavior, click on "InternalFrame #1" and then on "InternalFrame#2." Then try to move the slider on InternalFrame#1 by clicking and dragging the slider head. The frame will become selected but the slider will not move until you click on it again.
Just as a note this does not happen with all components...any type of AbstractButton seems to work fine in the situations of switching back and forth between frames.
Has anyone encountered this behavior before? Is there some kind of a workaround? Am I not noticing something?
Thanks in advance,
Marie
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import java.awt.event.*;
import java.awt.*;
public class InternalFrameDemo extends JFrame {
JDesktopPane desktop;
public InternalFrameDemo() {
super("InternalFrameDemo");
//Make the big window be indented 50 pixels from each edge
//of the screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height-inset*2);
//Quit this app when the big window closes.
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
//Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
createFrame(); //Create first window
setContentPane(desktop);
//Make dragging faster:
desktop.putClientProperty("JDesktopPane.dragMode", "outline");
}
protected void createFrame() {
MyInternalFrame frame = new MyInternalFrame();
MyInternalFrame frame2 = new MyInternalFrame();
frame.setVisible(true);
frame2.setVisible(true); //necessary as of kestrel
frame.setLocation(200, 10);
frame2.setLocation(200, 400);
desktop.add(frame);
desktop.add(frame2);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}
public static void main(String[] args) {
InternalFrameDemo frame = new InternalFrameDemo();
frame.setVisible(true);
}
}

import javax.swing.JInternalFrame;
import java.awt.*;
import javax.swing.*;
public class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;
JSlider slider;
public MyInternalFrame() {
super("InternalFrame #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
//...Create the GUI and put it in the window...
//...Then set the window size or call pack...
setSize(300,300);
//Set the window's location.
slider = new JSlider(0, 100, 50);
getContentPane().add(slider);
}
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!