gpt4 book ai didi

java JList 大小

转载 作者:行者123 更新时间:2023-12-02 08:18:19 26 4
gpt4 key购买 nike

嗨,我想将 JList 高度设置为屏幕高度

public Locations() {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
screenWidth = screen.width;
screenHeight = screen.height;
initComponents();
}

private void initComponents() {
setLayout(new GroupLayout());
add(getJScrollPane0(), new Constraints(new Leading(8, 100, 10, 10), new Leading(5, 135, 10, 10)));
setSize(1366, 768);
}

private JScrollPane getJScrollPane0() {
if (jScrollPane0 == null) {
jScrollPane0 = new JScrollPane();
jScrollPane0.setSize(screenWidth, screenHeight);
jScrollPane0.setViewportView(getJList0());
}
return jScrollPane0;
}

private JList getJList0() {
if (jList0 == null) {
jList0 = new JList();
jList0.setSize(400, screenHeight);
DefaultListModel listModel = new DefaultListModel();
listModel.addElement("item0");
listModel.addElement("item1item1item1item1item1");
listModel.addElement("item2");
listModel.addElement("item3");
jList0.setModel(listModel);
}
return jList0;
}

private static void installLnF() {
try {
String lnfClassname = PREFERRED_LOOK_AND_FEEL;
if (lnfClassname == null)
lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lnfClassname);
} catch (Exception e) {
System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
+ " on this platform:" + e.getMessage());
}
}

/**
* Main entry of the class.
* Note: This class is only created so that you can easily preview the result at runtime.
* It is not expected to be managed by the designer.
* You can modify it as you like.
*/
public static void main(String[] args) {
installLnF();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Locations");
Locations content = new Locations();
content.setPreferredSize(content.getSize());
frame.add(content, BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}

但是列表大小就像我在编辑器中绘制的一样,如何更改它?

编辑:

我已经通过添加解决了问题

add(getJScrollPane0(), new Constraints(new Leading(8, 100, 10, 10), new Leading(5, screenHeight - 115, 10, 10)));

最佳答案

关于java JList 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5934686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com