शुरू में मैं एक डेक छवि और एक पाठ "डेक" बस छवि है जो ठीक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
पैनल जोड़ने के लिए, मेरे पूरे जीयूआई लग रहा है नीचे है डिजाइन गड़बड़ कर दिया गया है। जैसा कि आप देख सकते हैं कि मेरी डेक छवि को मेरे ग्रिडलेआउट की पहली पंक्ति के साथ ठीक से संरेखित नहीं किया गया है और मेरा टेक्स्ट "डेक" कुछ विस्तृत स्थान से अलग किया गया है।
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"
सिर्फ सही डेक छवि के नीचे से तालमेल किया जाना है, लेकिन मैं इसे पाने के लिए नहीं कर पा रहे।