Java - Cambiar tamaño BoxLayout --- Urge antes de Martes

 
Vista:
sin imagen de perfil

Cambiar tamaño BoxLayout --- Urge antes de Martes

Publicado por Will (1 intervención) el 22/10/2017 20:56:52
Objetivo
Hecho-por-mi

Buenas noches programadores,

estamos empezando en clase con Java e interfaces de usuario asi que perdonad que la pregunta sea totalmente novata, pero lo que me ocurre es que tengo que hacer el programa que aparece en "Objetivo.png" adjuntado y de momento he hecho la otra imagen. ACLARACION: LA PRIMERA IMAGEN ES A LO QUE DEBO LLEGAR Y LA SEGUNDA, COMO ESTA MI PROGRAMA ACTUALMENTE

Es decir, lo que me ocurre es que no me cambia el tamaño los paneles del BoxLayout y el JSlider de velocidad no me aparece exactamente donde quiero.

Es un trabajo para el Martes pero agradeceria cualquier ayuda. Mi teoria de momento es que me estoy haciendo la picha un lio, como auqqel que dice, con los private y static y al final.... meh.

En definitiva, DEJO EL CODIGO A CONTINUACION, si alguien se le ocurre donde esta el error cualquier ayuda es bien recibida. MUCHAS GRACIAS!


CODIGO:

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package ejercicio4;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.*;
/**
 *
 * @author guill
 */
public class Ejercicio4 extends JFrame
{
    /*private JPanel principal, aire, aireflow, marca, marcabox, velobox, combustible, botones;
    private JLabel velocidad, marca1;
    private JCheckBox airebox;
    private JComboBox lista;
    private JRadioButton diesel, gasolina;
    private JSlider slider;*/
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        JFrame fr = new JFrame("Caracteristicas Vehiculos");
 
        //COMPLETAR BORDER LAYOUT AIRE ------- PANEL 1
        JPanel aire = new JPanel(new BorderLayout());
        JPanel aireflow = new JPanel(new FlowLayout());
        JCheckBox airebox = new JCheckBox ("Aire Acondicionado");
 
        aireflow.add(airebox);
        aire.add(aireflow, BorderLayout.NORTH);
 
        aire.setSize(500,200);
        aire.setVisible(true);
 
        //COMPLETAR PANEL COMBUSTIBLE ------- PANEL 2
        JPanel combustible = new JPanel(new BorderLayout());
        JPanel botones = new JPanel(new FlowLayout());
 
        JRadioButton diesel = new JRadioButton("Diesel");
        JRadioButton gasolina = new JRadioButton("Gasolina");
 
        botones.add(diesel);
        botones.add(gasolina);
 
        combustible.add(botones, BorderLayout.NORTH);
 
        combustible.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 153, 255)));
        combustible.setBorder(javax.swing.BorderFactory.createTitledBorder("Combustible"));
        combustible.setSize(495,200);
        combustible.setVisible(true);
 
        //COMPLETAR BORDER LAYOUT MARCA ------- PANEL 3
        JPanel marca = new JPanel(new BorderLayout());
        JPanel marcabox = new JPanel(new FlowLayout());
        JPanel velobox = new JPanel(new FlowLayout());
        JLabel marca1 = new JLabel("Marca");
        JLabel velocidad = new JLabel("Velocidad");
        JComboBox lista = new JComboBox();
 
        JSlider slider = new JSlider(JSlider.HORIZONTAL, 50, 200, 100);
        slider.setPaintTicks(true);
        slider.setMajorTickSpacing(30);
        slider.setPaintLabels(true);
 
        lista.addItem("SEAT");
        lista.addItem("FORD");
        lista.addItem("TRACTOR");
        lista.addItem("COSECHADORA");
        lista.addItem("EMPACADORA");
 
        marcabox.add(marca1);
        marcabox.add(lista);
 
        velobox.add(velocidad);
        velobox.add(slider);
 
        marca.add(marcabox, BorderLayout.NORTH);
        marca.add(velobox, BorderLayout.CENTER);
 
        marca.setSize(500, 300);
        marca.setVisible(true);
 
        //COMPLETAR BOX LAYOUT PRINCIPAL
        JPanel principal = new JPanel();
        principal.setLayout(new BoxLayout(principal, BoxLayout.Y_AXIS));
        principal.add(aire);
        principal.add(combustible);
        principal.add(marca);
 
        principal.setVisible(true);
 
        //COMPLETAR JFRAME
        fr.add(principal);
        fr.setVisible(true);
        fr.setSize(500, 600);
    }
 
}
 
/*FALTA:
 - DEMASIADO ARRIBA LA BARRA
 - TAMAÑOS
*/
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder