I have been experiencing some really weird problems with gtk_label text positioning.
I have a gtk_label positioned on a fixed container, the label has been set to:
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
However when a single word is present in the label, instead of getting centered it gets left aligned.
If I unset gtk_label_set_line_wrap(GTK_LABEL(label), TRUE)
to FALSE
the word then appears in the center of the label, but I lose wrapping.
How should this be fixed?
答案 0 :(得分:2)
来自documentation(强调我的):
gtk_label_set_justify()
设置标签文本中的线条相对于彼此的对齐方式。
GTK_JUSTIFY_LEFT
是首次使用gtk_label_new()
创建窗口小部件时的默认值。如果您想要将标签的对齐方式设置为整体,请改用gtk_misc_set_alignment()
。gtk_label_set_justify()
对仅包含一行的标签没有影响。
正如上面引用中所述,您可能希望在调用public void WinnerCheck()
{
if (m_allButtons[0][0].getText() == m_allButtons[0][1].getText() && m_allButtons[0][1].getText() == m_allButtons[0][2].getText())
{
DisableAllButtons();
}
else if (m_allButtons[1][0].getText() == m_allButtons[1][1].getText() && m_allButtons[1][1].getText() == m_allButtons[1][2].getText())
{
DisableAllButtons();
}
}
private void AddAllEventHandlers()
{
if (m_allButtons != null)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
JButton currentButton = m_allButtons[i][j];
currentButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
ChangeButtonText(currentButton);
WinnerCheck();
}
});
}
}
}
}
之前添加对gtk_misc_set_alignment()
函数的调用,并将xalign
参数设置为0.5
。