日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java scrollpane源码_JScrollPane用法 Java实例

發(fā)布時間:2023/12/1 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java scrollpane源码_JScrollPane用法 Java实例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

時間:2019-10-07

概述:JScrollPane 滾動條

在Java中使用JScrollPane的例子,特別是滾動條的設(shè)置等,程序代碼中將設(shè)置水平與垂直表頭、設(shè)置scrollPane的邊角圖案、設(shè)置scrollPane的邊框凹陷立體邊框。適時水平滾動軸的參數(shù)設(shè)置等內(nèi)容:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

public class JScrollPaneDemo implements ActionListener {

private JScrollPane scrollPane;

public JScrollPaneDemo() {

JFrame f = new JFrame("JScrollPaneDemo");

Container contentPane = f.getContentPane();

JLabel label1 = new JLabel(new ImageIcon(".\\icons\\Hill.jpg"));

JPanel panel1 = new JPanel();

panel1.add(label1);

scrollPane = new JScrollPane();

//設(shè)置窗口顯示的內(nèi)容窗格為panel1

scrollPane.setViewportView(panel1);

//設(shè)置水平與垂直表頭

scrollPane.setColumnHeaderView(new JLabel("水平表頭"));

scrollPane.setRowHeaderView(new JLabel("垂直表頭"));

//設(shè)置scrollPane的邊框凹陷立體邊框。

scrollPane.setViewportBorder(BorderFactory

.createBevelBorder(BevelBorder.LOWERED));

//設(shè)置scrollPane的邊角圖案

scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, new JLabel(

new ImageIcon(".\\icons\\Sunset.jpg")));

scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new JLabel(

new ImageIcon(".\\icons\\Sunset.jpg")));

JPanel panel2 = new JPanel(new GridLayout(3, 1));

JButton b = new JButton("顯示水平滾動軸");

b.addActionListener(this);

panel2.add(b);

b = new JButton("不要顯示水平滾動軸");

b.addActionListener(this);

panel2.add(b);

b = new JButton("適時顯示水平滾動軸");

b.addActionListener(this);

panel2.add(b);

contentPane.add(panel2, BorderLayout.WEST);

contentPane.add(scrollPane, BorderLayout.CENTER);

f.setSize(new Dimension(350, 220));

f.show();

f.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

}

public void actionPerformed(ActionEvent e) {

if (e.getActionCommand().equals("顯示水平滾動軸")) {

scrollPane.setHorizontalScrollBarPolicy

(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

}

if (e.getActionCommand().equals("不要顯示水平滾動軸")) {

scrollPane.setHorizontalScrollBarPolicy

(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

}

if (e.getActionCommand().equals("適時顯示水平滾動軸")) {

scrollPane.setHorizontalScrollBarPolicy

(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

}

scrollPane.revalidate();//重新顯示JScrollPane形狀。

}

public static void main(String[] args) {

new JScrollPaneDemo();

}

}

總結(jié)

以上是生活随笔為你收集整理的java scrollpane源码_JScrollPane用法 Java实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。