
Problemas al redimensionar componentes Java Swing
Publicado por Emmanuel (1 intervención) el 12/09/2016 04:26:18
Tengo algunos problemas al redimensionar un elemento que está dentro de un objeto que, lo que busco haga por medio del evento del frame, es que las dimensiones mínimas, máximas y prdeterminadas de su ancho las defina tomando como base el ancho de la ventana, pero parece no funcionar, pues no lo hace y se sigue manteniendo su mismo ancho.
Este es mi código:
y este es la clase principal que llama a un objeto de tipo
Lo anexo para que puean ver el problema que tengo al probar las dimensiones del JList.
Muchas gracias por su ayuda
1
JList
1
JSplitPane
1
componentResized()
Este es mi código:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.*;
public class ComVisor extends JFrame
{
private JList imagesList;
private JPanel imagePanel;
private JSplitPane mainPanel;
private JScrollPane scrollPanelRight;
private int width;
public ComVisor(String nameApplication)
{
setFrame(nameApplication);
setComponents();
}
private void setFrame(String nameApplication)
{
setLayout(new BorderLayout(1, 3));
setTitle(nameApplication);
setMinimumSize(new Dimension(400, 200));
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize()));
setLocationRelativeTo(null);
this.addWindowListener(
new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
JOptionPane.showMessageDialog(ComVisor.this, nameApplication + "-Salida");
return;
}
}
);
this.addComponentListener(
new ComponentAdapter()
{
@Override
public void componentResized(ComponentEvent E)
{
width = getWidth();
scrollPanelRight.setPreferredSize(new Dimension(width / 3, 0));
scrollPanelRight.setMinimumSize(new Dimension(width / 7, 0));
scrollPanelRight.setMaximumSize(new Dimension(width / 5 * 4, 0));
repaint();
return;
}
}
);
}
private void setComponents()
{
String[] a = {"dsdsdsd", "dsdsdkkhskj", "dskhkjdhskjdhksdh", "sdskdhskjhds"};
JButton b = new JButton("Soy un boton xD");
JPanel p = new JPanel();
imagesList = new JList(a);
p.add(b);
imagesList.setVisibleRowCount(100);
scrollPanelRight = new JScrollPane(imagesList);
mainPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollPanelRight, p);
add(mainPanel, BorderLayout.CENTER);
return;
}
private class Manejador implements ActionListener
{
@Override
public void actionPerformed(ActionEvent listener)
{
return;
}
}
}
y este es la clase principal que llama a un objeto de tipo
1
ComVisor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import static javax.swing.SwingUtilities.invokeLater;
public class Principal
{
public static void main(String[] args)
{
invokeLater(
new Runnable()
{
@Override
public void run()
{
new ComVisor("ComVisor").setVisible(true);
return;
}
}
);
return;
}
}
Lo anexo para que puean ver el problema que tengo al probar las dimensiones del JList.
Muchas gracias por su ayuda
Valora esta pregunta


0