Win a copy of Machine Learning with TensorFlow this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

JTextArea problems in GridbagLayout

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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));
}
}

}
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Mike Croteau
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NICE!!! Thanks!!
 
Mike Croteau
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NICE!! THANKS!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic