gpt4 book ai didi

java - 马蒂斯垂直流布局

转载 作者:行者123 更新时间:2023-12-01 13:25:39 26 4
gpt4 key购买 nike

有没有办法创建 Netbeans Matisse 垂直流布局,例如:

Vertical Flow Layout

但是 Netbeans Matisse Flow Layout 创建如下: Horizontal Flow Layout

最佳答案

FlowLayout 会自动“包裹”宽度超出其所在容器边界的组件。因此,为了实现我认为,您正在尝试完成后,您所需要做的就是像您所做的那样设置 FlowLayout,并将 JTextField 调整为适当的宽度。

注意:“我的想法”是对以下事实的尖锐批评:您的问题并不能真正帮助我们确切地了解您想要实现的目标。

五个 JTextField:

enter image description here

请注意,如果您调整其中一个的大小,它将“包裹”其他的:

enter image description here

您可以同时选择多个组件并调整其大小:

enter image description here

我将宽度更改为 250: enter image description here

中提琴:

enter image description here

代码:

public class NewJFrame2 extends javax.swing.JFrame {

/**
* Creates new form NewJFrame2
*/
public NewJFrame2() {
initComponents();
setSize(287,200);
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new java.awt.FlowLayout());

jTextField1.setText("jTextField1");
jTextField1.setPreferredSize(new java.awt.Dimension(250, 20));
getContentPane().add(jTextField1);

jTextField2.setText("jTextField2");
jTextField2.setPreferredSize(new java.awt.Dimension(250, 20));
getContentPane().add(jTextField2);

jTextField3.setText("jTextField3");
jTextField3.setPreferredSize(new java.awt.Dimension(250, 20));
getContentPane().add(jTextField3);

jTextField4.setText("jTextField4");
jTextField4.setPreferredSize(new java.awt.Dimension(250, 20));
getContentPane().add(jTextField4);

jTextField5.setText("jTextField5");
jTextField5.setPreferredSize(new java.awt.Dimension(250, 20));
getContentPane().add(jTextField5);

pack();
}// </editor-fold>

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame2().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
// End of variables declaration
}

关于java - 马蒂斯垂直流布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21820769/

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