Results 21 to 24 of 24
Thread: JScrollPane issues.
- 02-03-2012, 08:48 PM #21
- 02-03-2012, 08:53 PM #22
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(); } }
- 02-03-2012, 09:09 PM #23
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Re: JScrollPane issues.
I wrote this, and it worked a treat:
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 :)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(); } }
- 02-03-2012, 09:11 PM #24
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Similar Threads
-
JScrollPane and viewport issues
By tbuchwalter in forum AWT / SwingReplies: 2Last Post: 10-15-2011, 11:03 PM -
JScrollPane issues - no autoscroll wished
By Flo in forum AWT / SwingReplies: 3Last Post: 08-18-2011, 01:17 PM -
JScrollPane Help
By Huskies in forum AWT / SwingReplies: 2Last Post: 08-06-2011, 06:06 PM -
JScrollPane
By UJJAL DHAR in forum New To JavaReplies: 12Last Post: 08-17-2010, 06:47 PM -
jscrollpane scroll issues
By kumar_gemi in forum AWT / SwingReplies: 11Last Post: 09-30-2009, 08:33 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks