我想讓我的多行標籤正確對齊......不知道爲什麼這太難了。我曾嘗試使用weightx並添加了一個空白jlabel並給它1.0的權重。我無法得到這個工作。這個想法是,一個人全部左對齊,另一個人右對齊。 (有點像發短信的應用程序)。任何人都可以提出建議我一直試圖找到類似的帖子,但有很多GBLayout問題的線程!GridBagConstraints不正確與GridBagConstraints.EAST對齊
JLabel rightLblName = new JLabel(npcName);
GridBagConstraints gbc_rightLblName = new GridBagConstraints();
gbc_rightLblName.anchor = GridBagConstraints.EAST;
gbc_rightLblName.insets = new Insets(0, 0, 5, 5);
gbc_rightLblName.gridx = 5;
gbc_rightLblName.gridy = 2;
DialogueJInternalFrame.dialoguePanel.add(rightLblName, gbc_rightLblName);
JLabel rightLblImage = new JLabel("");
rightLblImage.setIcon(new ImageIcon(SpriteSheetCutter.makeColorTransparent((BufferedImage) SpriteStore.get().getSprite(npcFilename).getImage())));
rightLblImage.setBorder(DialogueJInternalFrame.raisedetched);
GridBagConstraints gbc_rightLblImage = new GridBagConstraints();
gbc_rightLblImage.insets = new Insets(0, 0, 5, 0);
gbc_rightLblImage.gridx = 6;
gbc_rightLblImage.gridy = 2;
DialogueJInternalFrame.dialoguePanel.add(rightLblImage, gbc_rightLblImage);
JMultilineLabel rightLblChatText = new JMultilineLabel(valuesSplit[1]);
GridBagConstraints gbc_rightLblChatText = new GridBagConstraints();
gbc_rightLblChatText.fill = GridBagConstraints.HORIZONTAL;
gbc_rightLblChatText.anchor = GridBagConstraints.EAST;
gbc_rightLblChatText.gridwidth = 7;
gbc_rightLblChatText.insets = new Insets(0, 0, 5, 0);
gbc_rightLblChatText.gridx = 0;
gbc_rightLblChatText.gridy = 3;
DialogueJInternalFrame.dialoguePanel.add(rightLblChatText, gbc_rightLblChatText);
底部的文本塊應該擁抱右側。謝謝你的幫助。
我從來沒有聽說過JMultilineLabel。你可以嘗試右邊的LBlChatText.setHorizontal或rightLblChatText.selAlignmentX。 –
它的自定義標籤實現...我認爲GBL不會爲我工作,因爲我已經嘗試過 – KisnardOnline