6
처음에 난 그냥GridBagLayout에 정렬되지 이미지가 제대로
public class GuiTut extends JPanel {
private GridBagConstraints c = new GridBagConstraints();
private JLabel deckLabel = new JLabel();
public GuiTut() {
setLayout(new GridBagLayout());
try {
deck = ImageIO.read(new File("resources/images/deck.jpg"));
} catch (Exception e) {}
c.gridx = 0;
c.gridy = 0;
JLabel deckPic = new JLabel(new ImageIcon(deck));
add(deckPic, c);
deckLabel.setText("Deck");
c.gridx = 0;
c.gridy = 1;
add(deckLabel, c);
}
하지만 내 gridLayout
패널을 추가 한 후
, 내 모든 GUI를 잘 보이는 이미지 아래 갑판의 이미지 및 텍스트 "데크"가 디자인이 엉망이되었습니다. 내 갑판 이미지가 내 gridLayout 의 첫 번째 행과 제대로 정렬되지 않아 내 텍스트 "갑판"이 몇 개의 넓은 공간으로 구분되어 있습니다.
public class GuiTut extends JPanel {
private GridBagConstraints c = new GridBagConstraints();
private JLabel deckLabel = new JLabel();
private JPanel gridLayoutPanel = new JPanel(new GridLayout(2, 0));
private JLabel[] label = new JLabel[14];
public GuiTut() {
setLayout(new GridBagLayout());
try {
card = ImageIO.read(new File("resources/images/card.jpg"));
} catch (Exception e) {}
for(int i = 0; i < 14; i++) {
label[i] = new JLabel(new ImageIcon(card);
gridLayoutPanel.add(label[i]);
}
try {
deck = ImageIO.read(new File("resources/images/deck.jpg"));
} catch (Exception e) {}
c.gridx = 0;
c.gridy = 0;
JLabel deckPic = new JLabel(new ImageIcon(deck));
add(deckPic, c);
deckLabel.setText("Deck");
c.gridx = 0;
c.gridy = 1;
add(deckLabel, c);
c.gridx = 1;
c.gridy = 0;
add(gridLayoutPanel, c);
}
내가 원하는 것은 갑판 이미지
는gridLayout
의 첫 번째 행과 바로 갑판 이미지 아래의 텍스트
"deck"
으로 정렬합니다하지만 난 그것을 얻을 수없는 것.