Hallo,
ich versuche gerade mit dem folgenden Code das JScrollPane "licenseScroll" scrollbar zu machen. In diesem wird der GNU Lizenz-Text eingfügt - ein langer Text, der eigentlich
ein automatisches Scrollen von JScrollPane auslösen sollte.
und das Weglassen beiden Policies hilft leider nichts. Die JScrollPane will einfach keine Scrollbalken anzeigen.
Sieht hier jemand, was ich vergessen habe oder falsch mache?
Besten Dank,
Wambui
ich versuche gerade mit dem folgenden Code das JScrollPane "licenseScroll" scrollbar zu machen. In diesem wird der GNU Lizenz-Text eingfügt - ein langer Text, der eigentlich
ein automatisches Scrollen von JScrollPane auslösen sollte.
Code:
licenseScroll.setAutoscrolls(true);
Code:
package com.company.workingdays; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; public class AboutFrame extends JFrame { private JButton closeButton = new JButton("Schliessen"); /** * Create the form of AboutFrame */ public AboutFrame() { initComponents(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setLocationRelativeTo(getOwner()); setSize(510, 350); setResizable(false); setTitle("Über WorkingDays"); } /** * ActionListeners of the form */ private void closeButtonActionPerformed(ActionEvent evt) { Container frame = closeButton.getParent(); do { frame = frame.getParent(); } while (!(frame instanceof JFrame)); ((JFrame) frame).dispose(); } /** * Components of the form */ private void initComponents() { /* Declaration and initialization of the variables */ JPanel contentPane = new JPanel(); JEditorPane aboutPane = new JEditorPane(); JEditorPane licensePane = new JEditorPane(); JScrollPane licenseScroll = new JScrollPane(); StringBuffer buffer = new StringBuffer(); /* End of declaration and initialization of the variables */ /* Create the resources from Jar file */ URL url = getClass().getResource("/resources/about.html"); InputStream input = getClass().getResourceAsStream("/resources/license"); InputStreamReader inputReader = new InputStreamReader(input); try { int len; while ((len = inputReader.read()) != -1) { buffer.append((char) len); } inputReader.close(); } catch (Exception ex) { ex.printStackTrace(); } contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); try { aboutPane.setPage(url); } catch (Exception ex) { ex.printStackTrace(); } aboutPane.setPreferredSize(new Dimension(490, 120)); aboutPane.setEditable(false); contentPane.add(aboutPane); licensePane.setPreferredSize(new Dimension(490, 120)); licensePane.setEditable(false); licensePane.setContentType("text/plain"); licensePane.setText(buffer.toString()); licenseScroll.setBorder(new TitledBorder(null, "Lizenz-Vereinbarung", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 12), Color.blue)); licenseScroll.setViewportView(licensePane); //licenseScroll.setAutoscrolls(true); licenseScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); licenseScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); contentPane.add(licenseScroll); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { closeButtonActionPerformed(evt); } }); contentPane.add(closeButton); pack(); } /** * Launch the application. */ public static void main(String[] args) { /* Create and display the form */ EventQueue.invokeLater(new Runnable() { public void run() { try { AboutFrame frame = new AboutFrame(); frame.setVisible(true); } catch (Exception ex) { ex.printStackTrace(); } } }); } }
Besten Dank,
Wambui
Comment