0
Kullanıcı arabirimi oluşturmaya çalışıyorum, ancak sipariş edilen bileşenleri yapamadım. JPanel bileşenimi ikinci resim gibi nasıl sipariş edebilirim, herhangi bir fikir var mı? Benim kodları nedenJFrame bileşenleri nasıl sipariş edilir?
burada MigLayout ile bu sorunu çözmek benim java kodları
import javax.swing.*;
import java.awt.*;
public class ApplicationWindow2 {
private JFrame mainJFrame;
private JPanel topPanel;
private JPanel centerPanel;
private JPanel bottomPanel;
public ApplicationWindow2(){
mainJFrame = new JFrame("setupbox");
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
mainJFrame.setMaximumSize(new Dimension(600,600));
mainJFrame.setMinimumSize(new Dimension((int) mainJFrame.getMaximumSize().getWidth()-1,(int) mainJFrame.getMaximumSize().getHeight()-1));
mainJFrame.setResizable(false);
mainJFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
int windowHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
int windowWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
mainJFrame.setLocation((windowWidth-mainJFrame.getWidth())/2, (windowHeight-mainJFrame.getHeight())/2);//
// components
mainJFrame.getContentPane().add(getTopPanel(), BorderLayout.PAGE_START);
mainJFrame.getContentPane().add(getCenterPanel(), BorderLayout.CENTER);
mainJFrame.getContentPane().add(getBottomPanel(), BorderLayout.PAGE_END);
mainJFrame.setVisible(true);
mainJFrame.pack();
}
private JPanel getTopPanel(){
if (topPanel == null){
topPanel = new JPanel();
topPanel.add(new JLabel("top panel"));
}
return topPanel;
}
private JPanel getBottomPanel(){
if(bottomPanel == null){
bottomPanel = new JPanel();
bottomPanel.add(new Label("bottom panel"));
}
return bottomPanel;
}
private JPanel getCenterPanel(){
if(centerPanel == null){
centerPanel = new JPanel();
centerPanel.setSize(new Dimension((int) mainJFrame.getMaximumSize().getWidth()-100,(int) mainJFrame.getMaximumSize().getHeight()-100));
centerPanel.setBorder(BorderFactory.createLineBorder(Color.black));
BoxLayout boxLayout = new BoxLayout(centerPanel, BoxLayout.Y_AXIS);
centerPanel.setLayout(boxLayout);
centerPanel.add(getTest());
centerPanel.add(getTest1());
centerPanel.add(Box.createVerticalStrut(30));
centerPanel.add(getTest());
}
return centerPanel;
}
private JPanel getTest(){
JPanel testPanel = new JPanel(new GridBagLayout());
testPanel.setMaximumSize(new Dimension(getCenterPanel().getWidth(), 40));
testPanel.setBorder(BorderFactory.createLineBorder(Color.black));
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.NONE;
c.gridy = 0;
c.insets = new Insets(5, 5, 5, 5);
JCheckBox box1 = new JCheckBox("asdasdasdasdasdasd");
c.gridx = 0;
c.anchor = GridBagConstraints.WEST;
testPanel.add(box1, c);
JLabel l3 = new JLabel("lbl3asdssssssssssssssssssssssssss");
l3.setPreferredSize(new Dimension(20,30));
l3.setBorder(BorderFactory.createLineBorder(Color.black));
c.gridx = 1;
c.anchor = GridBagConstraints.LINE_END;
testPanel.add(l3, c);
return testPanel;
}
private JPanel getTest1(){
JPanel testPanel = new JPanel(new GridBagLayout());
testPanel.setMaximumSize(new Dimension(getCenterPanel().getWidth(), 40));
testPanel.setBorder(BorderFactory.createLineBorder(Color.black));
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.NONE;
c.gridy = 0;
c.insets = new Insets(5, 5, 5, 5);
JCheckBox box1 = new JCheckBox("aass1133");
c.gridx = 0;
c.anchor = GridBagConstraints.LINE_START;
testPanel.add(box1, c);
JLabel l3 = new JLabel("lbl3as");
l3.setPreferredSize(new Dimension(20,30));
l3.setBorder(BorderFactory.createLineBorder(Color.black));
c.gridx = 1;
c.anchor = GridBagConstraints.LINE_END;
testPanel.add(l3, c);
return testPanel;
}
}
'JTable'? 'MigLayout'? – MadProgrammer
Hücrenin farklı boyutunu migLayout olarak ayarlayabilir miyiz? ve intellij'i nasıl ithal edebiliriz? iyi gibi görünüyor – enes
Ben kişisel olarak 'MigLayout' kullanmayın, ama bu tür sorunları çözebilir önerildi. Temel olarak, Jar dosyasını indirmeniz ve projenize eklemeniz gerekir. Intellij ile aşina değil: P – MadProgrammer