Tengo un JPanel que contiene una JToolbar (incluidos algunos botones sin texto) y una JTable y necesito habilitar/deshabilitar (hacer que los widgets internos no se puedan hacer clic). Intenté esto:Java Swing: Activando/Desactivando todos los componentes en JPanel
JPanel panel = ....;
for (Component c : panel.getComponents()) c.setEnabled(enabled);
pero no funciona. ¿Existe una solución mejor y más genérica para habilitar/deshabilitar todos los componentes internos en un JPanel?
he resuelto parcialmente mi problema utilizando JLayer partir de este ejemplo http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html:
layer = new JLayer<JComponent>(myPanel, new BlurLayerUI(false));
.....
((BlurLayerUI)layer.getUI()).blur(...); // switch blur on/off
class BlurLayerUI extends LayerUI<JComponent> {
private BufferedImage mOffscreenImage;
private BufferedImageOp mOperation;
private boolean blur;
public BlurLayerUI(boolean blur) {
this.blur = blur;
float ninth = 1.0f/9.0f;
float[] blurKernel = {
ninth, ninth, ninth,
ninth, ninth, ninth,
ninth, ninth, ninth
};
mOperation = new ConvolveOp(
new Kernel(3, 3, blurKernel),
ConvolveOp.EDGE_NO_OP, null);
}
public void blur(boolean blur) {
this.blur=blur;
firePropertyChange("blur", 0, 1);
}
@Override
public void paint (Graphics g, JComponent c) {
if (!blur) {
super.paint (g, c);
return;
}
int w = c.getWidth();
int h = c.getHeight();
if (w == 0 || h == 0) {
return;
}
// Only create the offscreen image if the one we have
// is the wrong size.
if (mOffscreenImage == null ||
mOffscreenImage.getWidth() != w ||
mOffscreenImage.getHeight() != h) {
mOffscreenImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
}
Graphics2D ig2 = mOffscreenImage.createGraphics();
ig2.setClip(g.getClip());
super.paint(ig2, c);
ig2.dispose();
Graphics2D g2 = (Graphics2D)g;
g2.drawImage(mOffscreenImage, mOperation, 0, 0);
}
@Override
public void applyPropertyChange(PropertyChangeEvent pce, JLayer l) {
if ("blur".equals(pce.getPropertyName())) {
l.repaint();
}
}
}
todavía tengo 2 problemas:
1) en el siguiente enlace eventos son en relación con el ratón solamente. ¿Cómo puedo administrar los eventos del teclado?
2) ¿Cómo puedo crear un efecto de "salida gris" en lugar de desenfoque?
Es posible ajustar la visibilidad del panel directamente por el uso de 'panel.setVisible (falso)' –
setVisible (falsa) hace que el componente " invisible "pero en realidad lo necesito todavía visible pero grisáceo". – Randomize
¿Este subproceso ayuda en absoluto? http://stackoverflow.com/a/305551/1417974 –