文本区域、表格等需要显示较多数据而空间又有限时,通常使用 JScrollPane 进行包裹以实现滚动显示。 JScrollPane 内包含一个视口 ?...表示 JScrollPane 的显示区域。 视口内包含一个需要滚动显示的组件,称为视图。
package com.swing; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JScrollPane...面板 * * 2:JScrollPane面板是带滚动条的面板,它也是一个面板,但是JScrollPane只能 * 放置一个组件,并且不可以使用布局管理器 * * 3:如果需要在JScrollPane...面板中放置多个组件,需要将多个组件放置在JPanel面板上, * 然后将JPanel作为一个整体组件添加到JScrollPane组件上。.../创建一个容器 //创建文本区域组件 JTextArea ta=new JTextArea(20,50); //创建JScrollPane...()面板对象,并将文本域对象添加到面板中 JScrollPane sp=new JScrollPane(ta); //将该面板添加到该容器中
model = new DefaultTableModel(data, columnNames); JTable table = new JTable(model); JScrollPane...scrollPane = new JScrollPane(table); frame.getContentPane().add(scrollPane); frame.setVisible...大表格可能超出窗口大小,需要添加JScrollPane。 避免方法:使用JScrollPane包裹JTable。 2. JTree JTree用于展示层次结构的数据,如文件系统或组织结构。...JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea("Enter your text here..."); JScrollPane...避免方法:使用JScrollPane包裹JTextArea。 问题2:未初始化文本。默认情况下,JTextArea为空。 避免方法:在创建JTextArea时设置初始文本。
javax.swing.JPanel; import javax.swing.border.EmptyBorder; import java.awt.GridBagLayout; import javax.swing.JScrollPane...Double.MIN_VALUE }; contentPane.setLayout(gbl_contentPane); JScrollPane...scrollPane = new JScrollPane(); GridBagConstraints gbc_scrollPane = new GridBagConstraints()...gbc_button.gridx = 0; gbc_button.gridy = 1; contentPane.add(button, gbc_button); JScrollPane...scrollPane_1 = new JScrollPane(); GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints
jScrollPane1; private JButton jb_delete; private JButton jb_modify; private JButton jb_search; private...= new JScrollPane(); courseTable = new JTable(); jPanel2 = new JPanel(); courseIdTxt = new JTextField...= new JScrollPane(); courseTable = new JTable(); setClosable(true); setIconifiable(true); setTitle("...jScrollPane1; private JButton jb_confirm; private JButton jb_underFull; DbUtil dbUtil = new DbUtil()...jScrollPane1; private JButton jb_search; private JTable studentTable; DbUtil dbUtil = new DbUtil();
JScrollPane面板,原因是因为JScrollPane面板是自带滚动条的,并且同时它也是一种容器,这也是在做相关开发时我们设置滚动条常用的一种方法。...使用JScrollPane面板时需要注意以下两个问题: JScrollPane面板中只能布置一个控件, JScrollPane面板不能使用布局管理器 因此如果想要在JScrollPane面板中显示多个控件...,就需要首先将控件布局在JPanel面板中,之后将JPanel面板作为一个整体组件添加到JScrollPane面板中, 通过下面程序对JScrollPane面板进行实践: 以下程序是在JScrollPane...public class JScrollPaneClass extends JFrame{ public JScrollPaneClass() { setTitle("JScrollPane面板...面板中添加一个文本框******************/ JTextArea jTextArea = new JTextArea(); JScrollPane jsp = new JScrollPane
jbtnDelete = new javax.swing.JButton(); jbtnFind = new javax.swing.JButton(); jScrollPane1...= new javax.swing.JScrollPane(); jListAddress = new javax.swing.JList(); jLabel1 = new...public Object getElementAt(int i) { return strings[i]; } }); jScrollPane1....setViewportView(jListAddress); add(jScrollPane1); jScrollPane1.setBounds(40, 70, 700...jScrollPane1; private javax.swing.JToggleButton jToggleButton1; private javax.swing.JButton
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane...jScrollPane = new JScrollPane(); static JTextArea jTextArea = new JTextArea(); boolean bool..., BorderLayout.CENTER); jScrollPane.getViewport().add(jTextArea); setSize(400, 400);...jScrollPane = new JScrollPane(); JTextArea jTextArea = new JTextArea(); // -----------------..., BorderLayout.CENTER); jScrollPane.getViewport().add(jTextArea); jPanel2.add(jPanel3
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane...outputArea = new JTextArea(70, 70); //输入区域 final JTextArea inputArea = new JTextArea(70, 70); final JScrollPane...outputScroll = new JScrollPane(outputArea); final JScrollPane inputScroll = new JScrollPane(inputArea...import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane...outputScroll = new JScrollPane(outputArea); final JScrollPane inputScroll = new JScrollPane(inputArea
= new javax.swing.JScrollPane(); jListInMain = new javax.swing.JList(); jScrollPane2....setViewportView(jListInDetail); add(jScrollPane2); jScrollPane2.setBounds(400, 110,...jScrollPane1; private javax.swing.JScrollPane jScrollPane2; // End of variables declaration/....setViewportView(jtxArea); add(jScrollPane2); jScrollPane2.setBounds(440, 100, 340,...jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextArea jtxArea
java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane... "3、版本:1.0.0\r\n" + "4、本程序使用java语言编写\r\n" + "5、本程序仅供学习交流使用" ); JScrollPane...js = new JScrollPane(textArea ); JPanel panel = new JPanel(); this.add(panel,BorderLayout.CENTER
jScrollPane1; 24 private javax.swing.JPanel mainPanel; 25 private javax.swing.JMenuBar menuBar...targetmail = new javax.swing.JTextField(); 69 send = new javax.swing.JButton(); 70 jScrollPane1...= new javax.swing.JScrollPane(); 71 infoShow = new javax.swing.JTextArea(); 72 menuBar....setName("jScrollPane1"); // NOI18N 96 97 infoShow.setColumns(20); 98 infoShow.setRows...(5); 99 infoShow.setName("infoShow"); // NOI18N 100 jScrollPane1.setViewportView(infoShow
javax.swing.border.EmptyBorder; import javax.swing.JTextField; import javax.swing.JTextArea; import javax.swing.JScrollPane...}); panel.add(nameField, BorderLayout.NORTH); nameField.setColumns(10); JScrollPane...scrollPane = new JScrollPane(); panel.add(scrollPane); personnelArea = new JTextArea...242); contentPane.add(panel_1); panel_1.setLayout(new BorderLayout(0, 0)); JScrollPane...scrollPane_1 = new JScrollPane(); panel_1.add(scrollPane_1); resultArea = new JTextArea
JTextArea textArea=new JTextArea(60,60); textArea.setText(readFromFile(filePath)); JScrollPane...scrollPanel=new JScrollPane(textArea); scrollPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS...); scrollPanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);...scrollPanel=new JScrollPane(textArea); scrollPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS...); scrollPanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane...= new JPanel(); bSort = new JButton("排序"); textArea.setEditable(false); // 设置水平和垂直方向滚动条总是出现 JScrollPane...scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jScrollPane1...= new javax.swing.JScrollPane(); listUsers = new javax.swing.JList(); jLabel1 = new....setViewportView(listUsers); add(jScrollPane1); jScrollPane1.setBounds(170, 170, 410...Variables declaration - do not modify private javax.swing.JLabel jLabel1; private javax.swing.JScrollPane...jScrollPane1; private javax.swing.JList listUsers; // End of variables declaration//GEN-END:
import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane...jsp = new JScrollPane(infoJTextArea); jsp.setBounds(10, 210, 480, 100); jsp.setVerticalScrollBarPolicy...(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); panel.add(jsp); loginButton.addActionListener(e -> {...jsp = new JScrollPane(infoJTextArea); jsp.setBounds(10, 210, 480, 100); jsp.setVerticalScrollBarPolicy...(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); panel.add(jsp); loginButton.addActionListener(e -> {
args) { test5 t5 = new test5(); } } 接下来就是菜单栏下面的文本编辑区域了,这里只需要用一个JTextArea就可以了,别忘了还有滚动条(JScrollPane...private static JTextArea edit_text_area; //private JTextArea edit_text_area; //编辑区域 private JScrollPane...scroll_bar; //可滚动的pane 里面添加edit_text_area就可以变为一个可以滚动的文本框,JScrollPane是一个pane,同时可以设置方向 public test5...同时对pane设置方向 */ public void initEditArea() { edit_text_area = new JTextArea(); scroll_bar = new JScrollPane...(edit_text_area); scroll_bar.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JScrollPane...public class TextEditer extends JFrame { private static final long serialVersionUID = 1L; private JScrollPane...fgColor); textArea.setBackground(bgColor); textArea.setLineWrap(true);// 超出边界自动换行 scrollPane = new JScrollPane
领取专属 10元无门槛券
手把手带您无忧上云