我试图在JTextArea和JButton中对齐文本的位置,但是对于我尝试的所有内容,要么没有任何反应,要么对齐仍然稍微偏离。
以下是: (您可以看到突出显示的选项,JButton(中心)略低于两侧的两个JTextAreas。)
以下是一些代码:
categoryFile[i][j] = tempButton;
categoryFile[i][j].setBackground(Color.white);
categoryFile[i][j].setForeground(Color.black);
categoryFile[i][j].setOpaque(true);
categoryFile[i][j].setFocusable(false);
categoryFile[i][j].setBorderPainted(false);;
categoryFile[i][j].setVerticalAlignment(SwingConstants.TOP);
categoryFile[i][j].setPreferredSize(new Dimension(500,10));
categoryFile[i][j].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openPDFWithOptions(filePath,fileName);
}
});
JPanel listRow = new JPanel();
listRow.setBackground(Color.white);
listRow.setLayout(new BorderLayout());
listRow.setPreferredSize(new Dimension(800, 40));
JTextArea category = new JTextArea(fileElements[0]);
category.setEditable(false);
JTextArea parent = new JTextArea(fileElements[1]);
parent.setEditable(false);
listRow.add(parent,BorderLayout.WEST);
listRow.add(categoryFile[i][j],BorderLayout.CENTER);
listRow.add(category,BorderLayout.EAST);
categoryLists[i].add(listRow,c);
现在我正在使用categoryFile[i][j].setVerticalAlignment(SwingConstants.TOP)
来更改ALMOST工作的JButton的位置。我也试过改变JTextAreas的垂直对齐方式,但没有改变。
如何在这些组件中对齐文本?