Por favor, alguien me puede decir como centrar una JInternalFrame, o talvez si hay alguna clase??
Estoy utilizando la clase Centering, que el código es, pero no me funciona para las JInternalframe??
import java.awt.Color;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author Cristhian
*/
public class Centering {
JDialog dialog;
public Centering(Frame f) {
dialog = new JDialog(f);
dialog.setSize(100,100);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.getContentPane().setBackground(Color.yellow);
}
private void setDialogLocation(Frame f) {
Rectangle r = f.getBounds();
int x = r.x + (r.width - dialog.getSize().width)/2;
int y = r.y + (r.height - dialog.getSize().height)/2;
dialog.setLocation(x, y);
}
private JPanel getChoices(final Frame f) {
JButton showDialog = new JButton("show dialog");
showDialog.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setDialogLocation(f);
dialog.setVisible(true);
}
});
JPanel panel = new JPanel();
panel.add(showDialog);
return panel;
}
public static void main(String[] args) {
JFrame f = new JFrame();
Centering test = new Centering(f);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(test.getChoices(f), "Last");
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}
Saludos cordiales,
Cristhian




