[英]Making a JList in netbeans Frame
i'm making an Jlist in Netbeans and i have written a code but the code dissapears not in my Jlist 我正在Netbeans中创建一个Jlist,我已经编写了一个代码,但代码消失在我的Jlist中
/** Creates new form Toetsenbordd */
public Toetsenbordd() {
initComponents();
initCustomComponents();
}
private void initCustomComponents(){
JList Lijstje;
JScrollPane Lijst;
String filename[]= {"Ard ","Astronauts",
"Behind the Scene Movie credits","DNA Research -- the Human Genome Project",
"Extract from The Adventures of Pinocchio","History of Photography",
"Hubble Space Telescope","Legends of Abraham Lincoln","Netiquette",
"Observations of the Father of Computing (1791 - 1871)","Rules of Baseball (from 1889)",
"Speeding up the strategy process","Stinging Insects","The Eight Tools for Creating New Values",
"The Life of Calamity Jane","The Little Match Girl (adapted)","The Tail of Peter Rabbit",
"Thoughts of Banjamin Franklin","What is the Cast","Yosemite National Park"
};
{
Lijstje = new JList(filename);
Lijstje.setFont(new Font("Arial",Font.PLAIN,15));
Lijst =new JScrollPane(Lijstje);
Lijst.setSize(410,200);
Lijst.setLocation(70,75);
Lijstje.setVisibleRowCount(6);
Lijstje.setSelectedIndex(0);
Lijstje.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//seting the border for filescroll
Lijst.setBorder(BorderFactory.createTitledBorder("CHOOSE TEST"));
add(Lijst);
}
}
It stands in the middle of my selfmade Jframe: 它位于我自制Jframe的中间:
But i want it there where it says item 1,2,3 但我希望它在那里说1,2,3项
First of all please don't start your variable names with capital letters, this is against the Java naming conventions . 首先请不要用大写字母开始你的变量名,这是违反Java命名约定的 。
setLocation
in your code implies that you want your Lijst
to have an absolute position. 代码中的setLocation
意味着您希望Lijst
具有绝对位置。 This is only possible when you are not using a LayoutManager, refer to this tutorial . 这仅在您不使用LayoutManager时才可用,请参阅本教程 。 To do that you need to set layout manager to null
explicitly because BorderLayout
is the default: 为此,您需要将布局管理器显式设置为null
因为BorderLayout
是默认值:
setLayout(null)
But it's not recommended to go with a null
layout manager, and you really should consider using the one from the list 但是不建议使用null
布局管理器,你真的应该考虑使用列表中的那个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.