Java, putting a JScrollList onto a JPanel

余生颓废 提交于 2019-12-20 07:03:50

问题


I am wondering if there is a way to add a JList on a JFrame with a JPanel. I am making a program and I searched all over the interwebs for an answer but I can't find one. Anyways Preferably the JList with a scrollpane (that works) if it is possible

Here is my code:

public static void main(String args[]) {
  JScrollPane scrollpane;
  JFrame frame = new JFrame();
   JList list;


    String categories[] = { "1", "2", "3","4", "5", "6", "7","8", "9", "10", "11", "12" };

    list = new JList(categories);
    JScrollPane scrollpane1 = new JScrollPane(list);

    frame.getContentPane().add(scrollpane1, BorderLayout.CENTER);
  MyClass sl = new MyClass();
frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setSize(300, 200);
frame.setVisible(true);


} 

来源:https://stackoverflow.com/questions/33204408/java-putting-a-jscrolllist-onto-a-jpanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!