S
S
Sergey Popov2015-12-13 19:31:59
Java
Sergey Popov, 2015-12-13 19:31:59

What to use for such an arrangement of elements?

ce8d6752feb14445b585d0ad60d3bd3c.png
It is necessary to cut down such an arrangement.
Menu - JMenuBar - done, it works.
Tabs - in JPanel BorderLayout - Works. The contents of the tabs display crookedly.
f9f9a8bb3afe4d73bac4bfac8ee74373.png
Tried through Box
Despite the given sizes (both through setSize, and through setMinimumSize, setMaximumSize, setPreferredSize) does not want to correctly display the button and the second panel. More specifically, it does not display them at all.
Help fix.
Main class code:

public class Display {
  JFrame frame;

  JMenuBar menubar = new JMenuBar();

  JMenu file = new JMenu("File");
  JMenu help = new JMenu("Help");

  JMenuItem start = new JMenuItem("Start");
  JMenuItem exit = new JMenuItem("Exit");
  JMenuItem about = new JMenuItem("About");

  JTabbedPane tabPane = new JTabbedPane();

  JPanel object = new ObjectPanel();
  JPanel man1 = new MovePanel();
  JPanel man2 = new MovePanel();
  JPanel man3 = new MovePanel();
  JPanel integral = new IntegralPanel();
  JPanel graphic = new GraphicsPanel();

  JPanel mainPanel = new JPanel();
  JPanel topPanel = new JPanel();
  JPanel bottomPanel = new JPanel();

  JButton start_b = new JButton("Start");
  JLabel l = new JLabel("Here goes some text");

  public Display() {
    frame = new JFrame();
    frame.setTitle("Горизонтальная плоскость");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800, 700);
    setPanels();

    file.add(start);
    file.add(exit);
    help.add(about);

    menubar.add(file);
    menubar.add(help);

    frame.setJMenuBar(menubar);
    frame.add(mainPanel);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(topPanel);
mainPanel.add(start_b);
mainPanel.add(bottomPanel);
    
    
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }

  private void setPanels() {
    tabPane.add("Объект", object);
    tabPane.add("Маневр 1", man1);
    tabPane.add("Маневр 2", man2);
    tabPane.add("Маневр 3", man3);
    tabPane.add("Интегрирование", integral);
    tabPane.add("График", graphic);
    
    topPanel.setSize(new Dimension(frame.getWidth(), frame.getHeight() / 2 - 25));
    topPanel.setLayout(new BorderLayout());
    topPanel.add(tabPane);
    
    bottomPanel.setSize(new Dimension(frame.getWidth(), frame.getHeight() / 2 - 25));
    bottomPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
    bottomPanel.add(l);
  }
}

Additional class code (only what is objectPanel)
public class ObjectPanel extends JPanel{
  JLabel b11 = new JLabel("b11");
  JLabel b12 = new JLabel("b12");
  JLabel b13 = new JLabel("b13");
  JLabel b21 = new JLabel("b21");
  JLabel b22 = new JLabel("b22");
  JLabel b23 = new JLabel("b23");
  
  JTextField b11_i = new JTextField();
  JTextField b12_i = new JTextField();
  JTextField b13_i = new JTextField();
  JTextField b21_i = new JTextField();
  JTextField b22_i = new JTextField();
  JTextField b23_i = new JTextField();
  
  GridBagLayout layout = new GridBagLayout();
  GridBagConstraints c = new GridBagConstraints();
  
  Box b = Box.createVerticalBox();
  Box b1 = Box.createHorizontalBox();
  Box b2 = Box.createHorizontalBox();
  public ObjectPanel(){
    this.setLayout(new FlowLayout(FlowLayout.LEFT));
    b.setPreferredSize(new Dimension(500, 200));
    b1.setPreferredSize(new Dimension(20, 200));
    b2.setPreferredSize(new Dimension(20, 200));
    b.setBorder(new TitledBorder("Матрица объекта"));
    this.add(b);
    b.add(b1);
    b.add(b2);
    
    b1.add(b11);
    b1.add(b11_i);
    b1.add(b12);
    b1.add(b12_i);
    b1.add(b13);
    b1.add(b13_i);
    b2.add(b21);
    b2.add(b21_i);
    b2.add(b22);
    b2.add(b22_i);
    b2.add(b23);
    b2.add(b23_i);
  }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question