僅在 Java 中顯示水平捲軸


若要僅顯示水平捲軸,請使用 VERTICAL_SCROLLBAR_NEVER 常量,它最終僅顯示水平捲軸。

以下示例展示瞭如何在 Java 中僅顯示水平捲軸 −

示例

package my;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class SwingDemo {
   public static void main(String args[]) {
      JFrame frame = new JFrame("Demo");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JButton button1 = new JButton("Online Compiler");
      JButton button2 = new JButton("Quiz");
      JButton button3 = new JButton("Questions and Answers");
      JButton button4 = new JButton("Videos");
      JButton button5 = new JButton("Tools");
      Box box = Box.createVerticalBox();
      box.setPreferredSize(new Dimension(900,900));
      box.add(button1);
      box.add(button2);
      box.add(button3);
      box.add(button4);
      box.add(button5);
      JScrollPane scrollPane = new JScrollPane();
      scrollPane.setViewportView(box);
      scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
      frame.add(scrollPane, BorderLayout.CENTER);
      frame.setSize(550, 250);
      frame.setVisible(true);
   }
}

輸出如下 −

更新於: 30-Jul-2019

439 瀏覽

啟動您的 事業

透過完成課程獲得認證

開始
廣告