Page 1 of 2 12 LastLast
Results 1 to 20 of 24
Like Tree1Likes

Thread: JScrollPane issues.

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

    Default JScrollPane issues.

    I've got a fairly good grasp on swing, so I dont know why this is causing so much of a problem for me, but there we go. There's gap in everyones knowledge x)

    Java Code:
    final JTextArea txtrPlaintext = new JTextArea();
    		JScrollPane scrollPane = new JScrollPane(txtrPlaintext);
    		txtrPlaintext.setMaximumSize(new Dimension(10,10));
    		txtrPlaintext.setRows(20);
    		txtrPlaintext.setWrapStyleWord(true);
    		txtrPlaintext.setLineWrap(true);
    That is the go i've given. I have absolutely no idea how to add a JScrollPane to a JTextArea. Can someone please point out where I'm going wrong? This isn't for a homework assignment. Just a little encryption app I'm writing :)

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: JScrollPane issues.

    Can you post a small simple program (a SSCCE) that compiles and executes and shows your problem?

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

    Default Re: JScrollPane issues.

    Well small might be a bit of an issue x) I've used window builder on Eclipse for most of my layout so it's jam packed with swing code. Basically the JScrollPane isn't showing up whatsoever, and the textArea is still getting bigger and bigger, when it gets full with text. Now My program is only gonna have a small physical area. (270,311) so I need to have a scroll function on the textArea. I'm just really confused as to why it won't appear. It's basically a lack of my understanding and I've looked at the API but I just don't see how i've gone wrong. I suppose what I'm asking is how would YOU go about adding a scroll pane to a text area? Maybe then I can compare it to my code and find out where i went wrong. I know that sounds suspiciously like I'm just asking for the answer, but I'm not. I just think that will be the quickest and most effective way for me to see how I've messed up.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: JScrollPane issues.

    I'd do this:
    Java Code:
            JTextArea txtrPlaintext = new JTextArea();
            JScrollPane scrollPane = new JScrollPane(txtrPlaintext);
            theContainer.add(scrollPane);

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

    Default Re: JScrollPane issues.

    See I've done this:

    Java Code:
    		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);
    Aside from the little changes that looks near enough the same as your's. The reason for the final modifier is because it won't let me add an event too it if it's not there.. so I didn't have much of a choice on that one x) I'm only left to assume that the problem must be later on in my code. although I dont know where! :(

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: JScrollPane issues.

    How can anyone test code without a JFrame and a main()? If you can not compile it, you can't test it.
    The code I posted put the text area in a scroll panel

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

    Default Re: JScrollPane issues.

    There is a Jframe and a main.. I just didn't include it in all in the post, because it would have been a horrific wall of text, and i know from experience that's not the best way to get an answer on these forums.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: JScrollPane issues.

    If you try making a SSCCE you may find the problem yourself. If you can not produce code that shows the problem then how can anyone find a fix if there is no shown problem? There needs to be some code that shows the problem so we have something to work with.

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

    Default Re: JScrollPane issues.

    I know, I'm just struggling to sift through the code that Windowbuilder generated. It's not that I don't have code to show you guys, it's that this code is just a wall of text. I really didn't want to be one of those posters that just dumps their code on you guys but there we go:

    Java Code:
    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("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.setText(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);
    	//	areaScrollPane.getViewport().add(txtrPlaintext);
    	//	appPanel.add(scrp);
    		appFrame.show();
    		// Display the appFrame.
    	}

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: JScrollPane issues.

    Where is the class statement and the import statements and the main() method?

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

    Default Re: JScrollPane issues.

    At the top:

    Java Code:
    import javax.swing.*;
    
    
    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 Cooney - 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("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.setText(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);
    	//	areaScrollPane.getViewport().add(txtrPlaintext);
    	//	appPanel.add(scrp);
    		appFrame.show();
    		// Display the appFrame.
    	}
    	
    	
    	
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		
    		MainWindow newWindow = new MainWindow();
    	}
    }

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: JScrollPane issues.

    It's a start. That code gives this compiler errors:
    Java Code:
    Running: F:\Java\jdk1.6.0_29\bin\javac.exe -Xlint -g -deprecation -classpath D:\JavaDevelopment\;.;..\. MainWindow.java
    
    MainWindow.java:19: cannot find symbol
    symbol  : class AESImplementation
    location: class MainWindow
        private AESImplementation cryptoTool;
                ^
    MainWindow.java:30: cannot find symbol
    symbol  : variable BorderLayout
    location: class MainWindow
            appFrame.getContentPane().add(appPanel, BorderLayout.CENTER);
                                                    ^
    MainWindow.java:40: cannot find symbol
    symbol  : class Dimension
    location: class MainWindow
            txtrPlaintext.setMaximumSize(new Dimension(10,10));
                                             ^
    MainWindow.java:50: cannot find symbol
    symbol  : class ActionListener
    location: class MainWindow
            encryptBut.addActionListener(new ActionListener() {
                                             ^
    MainWindow.java:73: cannot find symbol
    symbol  : class ActionListener
    location: class MainWindow
            btnDecrypt.addActionListener(new ActionListener() {
                                             ^
    MainWindow.java:99: cannot find symbol
    symbol  : variable ComponentPlacement
    location: class MainWindow
                                .addPreferredGap(ComponentPlacement.RELATED, 63, Short.MAX_VALUE)
                                                 ^
    MainWindow.java:96: cannot find symbol
    symbol  : variable Alignment
    location: class MainWindow
                            .addComponent(txtrPlaintext, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                                                         ^
    MainWindow.java:95: cannot find symbol
    symbol  : variable Alignment
    location: class MainWindow
                        .addGroup(gl_appPanel.createParallelGroup(Alignment.LEADING)
                                                                  ^
    MainWindow.java:92: cannot find symbol
    symbol  : variable Alignment
    location: class MainWindow
                gl_appPanel.createParallelGroup(Alignment.LEADING)
                                                ^
    MainWindow.java:112: cannot find symbol
    symbol  : variable Alignment
    location: class MainWindow
                        .addGroup(gl_appPanel.createParallelGroup(Alignment.BASELINE)
                                                                  ^
    MainWindow.java:111: cannot find symbol
    symbol  : variable ComponentPlacement
    location: class MainWindow
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                                         ^
    MainWindow.java:109: cannot find symbol
    symbol  : variable ComponentPlacement
    location: class MainWindow
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                                         ^
    MainWindow.java:105: cannot find symbol
    symbol  : variable Alignment
    location: class MainWindow
                gl_appPanel.createParallelGroup(Alignment.TRAILING)
                                                ^
    MainWindow.java:122: warning: [deprecation] show() in java.awt.Window has been deprecated
            appFrame.show();
                    ^
    13 errors
    1 warning
    
    14 error(s)

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

    Default Re: JScrollPane issues.

    Apologies. Eclipse had hidden the rest of the import statements!

    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("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.setText(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);
    	//	areaScrollPane.getViewport().add(txtrPlaintext);
    	//	appPanel.add(scrp);
    		appFrame.show();
    		// Display the appFrame.
    	}
    	
    	
    	
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		
    		MainWindow newWindow = new MainWindow();
    	}
    }
    The other missing symbol is AESImplementation. That has no relation whatsoever too the swing code, other than when the encrypt button is clicked, it encryps the value in the plaintext box. I didn't really feel it was necessary to include it.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: JScrollPane issues.

    What is supposed to happen?
    I enter a long string at the top and press Encrypt and I get: Keys must be 16 characters long, a.k.a: A 128 bit key.

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

    Default Re: JScrollPane issues.

    It'll encrypt in my 128 bit aes implementation. The top is for a 128 bit key x). All that stuff works perfectly. It won't work for you, because you don't have the AESImplementation class. It's just adding the scrollpane that won't work!

    The reason why you have that message though is because you are meant to put in a string of 16 ascii characters in the top, and plaintext in the bottom!

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: JScrollPane issues.

    you are meant to put in a string
    For testing you should provide the correct input. For example:
    Java Code:
            txtrKey.setText("1234567890123456"); //"Key");
    I don't see any scrollpane in this code.

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JScrollPane issues.

    Don't do this:

    Java Code:
    txtrPlaintext.setMaximumSize(new Dimension(10,10));
    You're constraining the size of the component held by the JScrollPane to be very small and the scrollpane won't work. If you're going to constrain the size of anything, set the preferredSize of the JScrollPane or its viewport.

    You really shouldn't be setting size of anything here but instead letting components size to their "natural" size and using appropriate layout managers to set sizes as needed.

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

    Default Re: JScrollPane issues.

    Aye, I did have that. But then when it worked it didn't make much sense to keep testing it!

    it is declared on line 40 :)

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

    Default Re: JScrollPane issues.

    Quote Originally Posted by Fubarable View Post
    Don't do this:

    Java Code:
    txtrPlaintext.setMaximumSize(new Dimension(10,10));
    You're constraining the size of the component held by the JScrollPane to be very small and the scrollpane won't work. If you're going to constrain the size of anything, set the preferredSize of the JScrollPane or its viewport.

    You really shouldn't be setting size of anything here but instead letting components size to their "natural" size and using appropriate layout managers to set sizes as needed.
    Thankyou for the suggestion Fub. I removed that code and it still won't work :(

  20. #20
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JScrollPane issues.

    Your problem is simply this: showing a JTextArea that holds text inside of a JScrollPane so that the scrollbars show up when the text is large enough. I suggest you create a small test program that just solves this issue, that has no other code (such as encryption/decryption code). In other words, an sscce. I would recommend that you create this without using a code generator. Let's see where your problems are without all the other distracting and unrelated code.
    Norm likes this.

Page 1 of 2 12 LastLast

Similar Threads

  1. JScrollPane and viewport issues
    By tbuchwalter in forum AWT / Swing
    Replies: 2
    Last Post: 10-15-2011, 11:03 PM
  2. JScrollPane issues - no autoscroll wished
    By Flo in forum AWT / Swing
    Replies: 3
    Last Post: 08-18-2011, 01:17 PM
  3. JScrollPane Help
    By Huskies in forum AWT / Swing
    Replies: 2
    Last Post: 08-06-2011, 06:06 PM
  4. JScrollPane
    By UJJAL DHAR in forum New To Java
    Replies: 12
    Last Post: 08-17-2010, 06:47 PM
  5. jscrollpane scroll issues
    By kumar_gemi in forum AWT / Swing
    Replies: 11
    Last Post: 09-30-2009, 08: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
  •