Domanda

Sto cercando di abbinare quanto segue

image pane

Durante l'implementazione di una gridbaglayout. Il GBL è l'unico modo in cui so di poter ottenere gli elementi di dimensioni diverse. So di poter fare qualcosa di simile all'immagine sopra ma non so come farlo con GBL. Sono anche pronto a prendere suggerimenti su un'idea migliore.

È stato utile?

Soluzione

Player GUI

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

class PlayerGui {

    public static void main(String[] args) {
        JPanel gui = new JPanel(new BorderLayout());
        gui.setBorder(new BevelBorder(BevelBorder.RAISED));

        JPanel north = new JPanel(new GridLayout(0,1,5,5));
        north.add(new JLabel("Player Name", SwingConstants.CENTER));

        JPanel tfConstrain = new JPanel(new FlowLayout(FlowLayout.CENTER));
        tfConstrain.add(new JTextField(18));

        north.add(tfConstrain);

        gui.add(north, BorderLayout.NORTH);

        JPanel center = new JPanel(new GridLayout(0,1,10,10));
        center.add(new JButton("On This Machine"));
        center.add(new JButton("Netowrk Based"));
        center.add(new JButton("Main Menu"));
        center.setBorder(new EmptyBorder(40,70,40,70));

        gui.add(center, BorderLayout.CENTER);

        JOptionPane.showMessageDialog(null, gui);
    }
}

Altri suggerimenti

Vedere Come usare Boxlayout, forse con alcuni riempitivo E un bel smussato Confine.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top