File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTextArea problems in GridbagLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea problems in GridbagLayout" Watch "JTextArea problems in GridbagLayout" New topic
Author

JTextArea problems in GridbagLayout

Mike Croteau
Greenhorn

Joined: Apr 09, 2007
Posts: 8
I keep having the same problems with my gridbag layout when trying to use JTextArea. Im either creating a faulty layout or Im not properly adding a JTextArea to my GridBagLayout. I pasted my code along with this post... can anyone give some incite to what I may be doing wrong or missing when trying to implement this? Thanks in advance!!

*******
CODE:

import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class ClassBrowserGui extends JFrame implements ActionListener{

JRadioButton privateRadio = new JRadioButton("Private");
JRadioButton protectedRadio = new JRadioButton("Protect");
JRadioButton publicRadio = new JRadioButton("Public");
JButton methodButton = new JButton("Methods");
JButton fieldButton = new JButton("Fields");
JButton interfaceButton = new JButton("Interfaces");
JButton classModButton = new JButton("Class Modifiers");
JButton constructorButton = new JButton("Constructors");
JLabel entClassLabel = new JLabel("Enter Class");
JTextField entClass = new JTextField(10);
JTextArea printout = new JTextArea(40, 40);
JPanel output = new JPanel();

private GridBagLayout layout;
private GridBagConstraints constraints;


public ClassBrowserGui(){
super("Class Browser");
layout = new GridBagLayout();
setLayout(layout);
//output.setLayout(layout);//setting frame layout
//output.setVisible(true);
//output.add(GridBagConstraints);
constraints = new GridBagConstraints();
//constraints.fill = GridBagConstraints.HORIZONTAL;
//JButton[] buttons = {methodButton, fieldButton, classModButton, interfaceButton, constructorButton};
addComponentsToGui();
addActionListeners();
setComponentsVisible();
}

private void setComponentsVisible() {
//buttons
methodButton.setVisible(true);
interfaceButton.setVisible(true);
fieldButton.setVisible(true);
constructorButton.setVisible(true);
classModButton.setVisible(true);
//text
printout.setVisible(true);
entClass.setVisible(true);

}

// private void addLabelTextRows(JLabel[] labels,
// JTextField[] textFields,
// GridBagLayout gridbag,
// Container container) {
//GridBagConstraints c = new GridBagConstraints();
//c.anchor = GridBagConstraints.EAST;
//int numLabels = labels.length;
//
//for (int i = 0; i < numLabels; i++) {
//c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
//c.fill = GridBagConstraints.NONE; //reset to default
//c.weightx = 0.0; //reset to default
//container.add(labels[i], c);
//
//c.gridwidth = GridBagConstraints.REMAINDER; //end row
//c.fill = GridBagConstraints.HORIZONTAL;
//c.weightx = 1.0;
//container.add(textFields[i], c);
//}
// }

private void addComponentsToGui() {
addComponent(entClassLabel, 0, 1, 1, 1);
addComponent(entClass, 1, 1, 1, 1 );
addComponent(methodButton, 1, 0, 1, 1);
addComponent(fieldButton, 2, 0, 1, 1);
addComponent(interfaceButton, 3, 0, 1, 1);
addComponent(constructorButton, 4, 0, 1, 1);
addComponent(classModButton, 5, 0, 1, 1);
addComponent(printout, 2, 1, 1, 1);

printout.getScrollableTracksViewportHeight();
printout.getScrollableTracksViewportWidth();
}

private void addActionListeners(){
methodButton.addActionListener(this);
}

private void addComponent(Component component, int row, int column, int width, int height) {

constraints.gridy = row;//set gridy
constraints.gridx = column;//set gridx
constraints.gridwidth = width;//set width
constraints.gridheight = height; //set height
//constraints.weightx = weightx;
//constraints.weighty = weighty;
//constraints.ipadx = ipadx;
//constraints.ipady = ipady;
layout.setConstraints(component, constraints);//set constraints
add(component);//add component
}

public void actionPerformed(ActionEvent e) {

if(e.getSource()== methodButton){
String a = "java.awt.GridBagConstraints";
ClassBrowser classBrowser = new ClassBrowser(a);
printout.setText(classBrowser.getPublicMethods(a));
}
}

}
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Mike Croteau
Greenhorn

Joined: Apr 09, 2007
Posts: 8
NICE!!! Thanks!!
Mike Croteau
Greenhorn

Joined: Apr 09, 2007
Posts: 8
NICE!! THANKS!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextArea problems in GridbagLayout