I've searched the internet for solutions and I don't seem to find one that works for me... In case you're wondering, I'm new to Swing. So, here's the thing, JButton
appears, but JTextArea
doesn't. I don't know what to do to solve this... Help me out guys...
public class FrameCreation
{
public JFrame createFrame(int width, int height, String name)
{
JFrame frame = new JFrame(name);
frame.setVisible(true);
frame.setSize(width, height);
frame.setLayout(null);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.DARK_GRAY);
return frame;
}
public JButton createButton(int width, int height, int xPos, int yPos, String text)
{
JButton button = new JButton(text);
button.setBounds(xPos, yPos, width, height);
button.setBackground(Color.GRAY);
button.setForeground(Color.WHITE);
return button;
}
public JTextArea createTextArea(int width, int height, int xPos, int yPos)
{
JTextArea txt = new JTextArea();
txt.setVisible(true);
txt.setBounds(xPos, yPos, width, height);
txt.setText("Help this poor JTextArea to appear on the frame...");
return txt;
}
}
public class Main
{
public static void main(String[] args)
{
FrameCreation mainFrame = new FrameCreation();
JFrame f = new FrameCreation().createFrame(600, 600, "My Frame");
f.add(mainFrame.createButton(100, 40, 10, 10, "Click me!"));
f.add(mainFrame.createTextArea(200, 200, 390, 10));
}
}