如何将滚动条添加到文本区域.我试过这个代码,但它没有用.
middlePanel=new JPanel();
middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Display Area"));
// create the middle panel components
display = new JTextArea(16, 58);
display.setEditable(false); // set textArea non-editable
scroll = new JScrollPane(display);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
//Add Textarea in to middle panel
middlePanel.add(scroll);
middlePanel.add(display);
Run Code Online (Sandbox Code Playgroud)
谢谢
如何在布局中将组件放置在特定位置.就像我想在第一行中放置2个文本框,在3个组合框下面.
但是当我试图将它们全部显示在一行中并且我使用了flowlayout时.我也使用过边框.当我调整大小时,组件的窗口大小将从边框出来.
你能建议我使用一些布局以及如何使用它吗?
这是我的代码:
topPanel=new JPanel();
topPanel.setLayout(new FlowLayout());
topPanel.setBorder(new TitledBorder(new EtchedBorder(), "Customer Data"));
CNameTextField = new JTextField (20); // create the Customer Name text field
CNameTextField.setEditable(true); // set editable text box
CIDLabel=new JLabel("Customer ID");
C_IDTextField = new JTextField (10);
C_IDTextField.setEditable(true); // set editable text box
topPanel.add(CNameTextField);
topPanel.add(C_IDTextField);
// Create and populate Room type combo box
roomTypeCombo = new JComboBox();
roomTypeCombo.addItem( "Budget($50)" );
// Create and populate Meal type combo box
mealCombo = new JComboBox();
mealCombo.addItem( "None" );
// Create and …Run Code Online (Sandbox Code Playgroud)