我正在尝试JList
使用来自ArrayList<String[]>
. 每个String[]
都是 ["I","am","an","example"] 的形式,我对输入形式无能为力 - 它来自第三方。我想要的只是一个JList
,每个都String[]
在不同的行上展开。但是,当我使用以下代码时,前几个字符被切断了JList
- 它切断了中间字符,因此它是像素而不是字符的问题。
下面的类被设置为程序其他地方的内容窗格JFrame
,我认为没有必要将其复制到这里,但如果它有用,那么我可以将其修剪并放上来查看。
public class BookScreen extends JPanel{
ListSelectionModel lsm;
ArrayList <String> atList;
JList atBox;
MainForm mf;
public BookScreen (MainForm mf){
//I'm aware this bit is clunky, it was a quick and dirty to test it displays
//properly before I cleaned it up
ArrayList<String[]> books= mf.getWorld().getBooks();
atList=new ArrayList();
for (String[] s:books){
atList.add(Arrays.toString(s));
}
//end clunky
atBox = new JList(atList.toArray());
lsm = atBox.getSelectionModel();
lsm.addListSelectionListener(new BookScreen.AtListSelectionHandler());
atBox.setVisibleRowCount(-1);
atBox.setLayoutOrientation(JList.HORIZONTAL_WRAP);
atBox.setLocation(0, 0);
atBox.setVisible(true);
this.add(atBox);
this.setVisible(true);
}
class AtListSelectionHandler implements ListSelectionListener{
@Override
public void valueChanged(ListSelectionEvent e){
}
}
}
问题截图: