Why does my JFrame stay empty, if I subclass JPanel and JFrame?

Recommendations:

  • Avoid using null layout as this makes your app difficult to upgrade and maintain and makes it potentially very ugly or even non-usable on boxes with different OS's or screen resolutions.
  • If you have your JPanel use a GridBagLayout and add a single component to it without using GridBagConstraints, it will be placed in the center of the JPanel.
  • You almost never have to or should extend JFrame and only infrequently need to extend JPanel. Usually it's better to enhance your GUI classes through composition rather than inheritance.
  • Avoid having your "view" or gui classes implement your listener interfaces. This is OK for "toy" programs, but as soon as your application gains any appreciable size or complexity, this gets hard to maintain.
Answer:1

Centered Button

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

public class LaunchPanel extends JPanel {

    private JButton startButton;

    public LaunchPanel() {
        int width = 200, height = 100;
        setPreferredSize(new Dimension(width, height));
        setLayout(new GridBagLayout());
        startButton = new JButton("Start");
        add(startButton);
        setBorder( new LineBorder(Color.RED, 2));
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null, new LaunchPanel());
            }
        });
    }
}
Answer:2

We're thinking of using Protocol Buffers for binary logging because: It's how we're encoding our objects anyway It is relatively compact, fast to read / write etc. That said, it isn't obvious how we ...

I am running Gnome on OpenSuse. As a result, my system look and feel is GTK+, which has numerous ugly problems (see some of them here). During development of my swing app, I can run the client from ...

Pesquisei muitos sites sobre como fazer isso usando apenas a chave da planilha, mas sem sucesso. Posso recuperá-lo, obter todos os dados que desejar, mas não consigo anexar uma nova linha a ele. Eu já ...

Eu implementei a gaveta de navegação que corresponde à altura dos pais. Agora acho que o botão de seta para trás que aparece depois de clicar no botão da gaveta de hambúrguer é realmente necessário aqui, pois não posso ...