Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24
Like Tree1Likes

Thread: JScrollPane issues.

  1. #21
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: JScrollPane issues.

    Moving to AWT/Swing

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: JScrollPane issues.

    By removing the IDE generated code, the scrollpane works:
    Java Code:
    import javax.swing.*;
    import javax.swing.GroupLayout.Alignment;
     
    import javax.swing.LayoutStyle.ComponentPlacement;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.Dimension;
    import java.awt.ScrollPane;
    import java.awt.BorderLayout;
    import javax.swing.border.MatteBorder;
    import java.awt.Color;
     
     
    public class MainWindow {
         
        /**
         * Provides the swing code for the Encryption App for 128 bit encryption.
         * 
         * @author Chris
         * @version Version 1
         * 
         */
         
    //    private AESImplementation cryptoTool;
         
        public MainWindow() {
            JFrame appFrame = new JFrame("Chris - AES 128");
            appFrame.setResizable(false);
            appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            appFrame.setSize(270,311);
            // Create the window.
            JPanel appPanel = new JPanel();
            appPanel.setSize(200,200);
            // Create the panel for the components.
            appFrame.getContentPane().add(appPanel, BorderLayout.CENTER);
            // Associate the panel with the window.
             
             
            final JTextArea txtrPlaintext = new JTextArea();
            JScrollPane scrPane = new JScrollPane(txtrPlaintext);
            scrPane.setToolTipText("Scroll bar");
            scrPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            scrPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            appPanel.add(scrPane);
    
            txtrPlaintext.setMaximumSize(new Dimension(10,10));
            txtrPlaintext.setRows(20);
            txtrPlaintext.setWrapStyleWord(true);
            txtrPlaintext.setLineWrap(true);
    
            final JTextArea txtrKey = new JTextArea();
            txtrKey.setLineWrap(true);
            txtrKey.setColumns(10);
            txtrKey.setText("1234567890123456"); //"Key");
             
            JButton encryptBut = new JButton("Encrypt");
            encryptBut.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    String keyText = txtrKey.getText();
                    String pText = txtrPlaintext.getText();
                    if(keyText.length() == 16 && (pText.length() > 0)) {
    //                cryptoTool = new AESImplementation(keyText);
                    txtrPlaintext.append("cryptoTool.encrypt(pText)");
                    }
                    else {
                        if(!(keyText.length() == 16))
                            txtrKey.setText("Keys must be 16 characters long, a.k.a: A 128 bit key.");
                        if(!(pText.equals(null)||!pText.equals(""))) 
                            txtrPlaintext.setText("Please enter some text here");
                    }
                }
            });
            encryptBut.setSize(25,25);
            encryptBut.setLocation(10,50);
             
             
            txtrPlaintext.setText("Plaintext");
             
            JButton btnDecrypt = new JButton("Decrypt");
            btnDecrypt.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    String keyText = txtrKey.getText();
                    String pText = txtrPlaintext.getText();
                    if(keyText.length() == 16 && (!pText.equals(null)||!pText.equals(""))) {
    //                cryptoTool = new AESImplementation(keyText);
                    txtrPlaintext.setText("cryptoTool.decrypt(pText)");
                    }
                    else {
                        if(!(keyText.length() == 16))
                            txtrKey.setText("Keys must be 16 characters long, a.k.a: A 128 bit key.");
                        if(!(pText.equals(null)||!pText.equals(""))) 
                            txtrPlaintext.setText("Please enter some text here");   
                    }
                }
            });
            btnDecrypt.setSize(encryptBut.getWidth(), btnDecrypt.getHeight());
    /*
            GroupLayout gl_appPanel = new GroupLayout(appPanel);
            gl_appPanel.setHorizontalGroup(
                gl_appPanel.createParallelGroup(Alignment.LEADING)
                    .addGroup(gl_appPanel.createSequentialGroup()
                        .addGap(27)
                        .addGroup(gl_appPanel.createParallelGroup(Alignment.LEADING)
                            .addComponent(txtrPlaintext, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                            .addGroup(gl_appPanel.createSequentialGroup()
                                .addComponent(encryptBut)
                                .addPreferredGap(ComponentPlacement.RELATED, 63, Short.MAX_VALUE)
                                .addComponent(btnDecrypt))
                            .addComponent(txtrKey, GroupLayout.PREFERRED_SIZE, 214, GroupLayout.PREFERRED_SIZE))
                        .addGap(27))
            );
            gl_appPanel.setVerticalGroup(
                gl_appPanel.createParallelGroup(Alignment.TRAILING)
                    .addGroup(gl_appPanel.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtrKey, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addComponent(txtrPlaintext, GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addGroup(gl_appPanel.createParallelGroup(Alignment.BASELINE)
                            .addComponent(encryptBut)
                            .addComponent(btnDecrypt))
                        .addGap(23))
            );
             
             
            appPanel.setLayout(gl_appPanel);
    */
            appFrame.add(scrPane,BorderLayout.EAST);      // This works  <<<<<<<<<<<<<<<<
        //  areaScrollPane.getViewport().add(txtrPlaintext);
        //  appPanel.add(scrp);
            appFrame.setVisible(true); //how();
            // Display the appFrame.
        }
         
         
         
        /**
         * @param args
         */
        public static void main(String[] args) {
             
            MainWindow newWindow = new MainWindow();
        }
    }

  3. #23
    christopherx is offline Member
    Join Date
    Oct 2011
    Posts
    92
    Rep Power
    0

    Default Re: JScrollPane issues.

    I wrote this, and it worked a treat:

    Java Code:
    import java.awt.Dimension;
    import javax.swing.*;
    public class Tester extends JFrame {
    	
    	public Tester()
    	{
    		setSize(300,300);
    		JPanel thisPanel = new JPanel();
    		add(thisPanel);
    		JTextArea thisArea = new JTextArea();
    		thisArea.setText("TEXT");
    		thisPanel.add(thisArea);
    		JScrollPane scrPane = new JScrollPane(thisArea);
    		scrPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    		scrPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    		thisArea.setLineWrap(true);
    		scrPane.setPreferredSize(new Dimension(100,100));
    		thisPanel.add(scrPane);
    		show();
    	}
    		
    	public static void main(String[] args)
    	{
    		Tester test = new Tester();
    	}
    }
    I'm gonna go through the code that eclipse has generated and see if I can't find out why my code in my mainwindow class won't work. I guess if this works, then there's no reason why it shouldn't work in my problem code! Thanks for the help guys :)

  4. #24
    christopherx is offline Member
    Join Date
    Oct 2011
    Posts
    92
    Rep Power
    0

    Default Re: JScrollPane issues.

    Riight! Well at least now I know where too look. I was hoping I could just comment all of that out but then the buttons and the rest of the GUI disapear :( I'll give it a good look. Thankyou for the help guys!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. JScrollPane and viewport issues
    By tbuchwalter in forum AWT / Swing
    Replies: 2
    Last Post: 10-16-2011, 12:03 AM
  2. JScrollPane issues - no autoscroll wished
    By Flo in forum AWT / Swing
    Replies: 3
    Last Post: 08-18-2011, 02:17 PM
  3. JScrollPane Help
    By Huskies in forum AWT / Swing
    Replies: 2
    Last Post: 08-06-2011, 07:06 PM
  4. JScrollPane
    By UJJAL DHAR in forum New To Java
    Replies: 12
    Last Post: 08-17-2010, 07:47 PM
  5. jscrollpane scroll issues
    By kumar_gemi in forum AWT / Swing
    Replies: 11
    Last Post: 09-30-2009, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •