import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Type2 extends JFrame {
private final JLabel q;
private final JLabel w;
private final JLabel text;
private final JTextArea text2;
public Type2(){
setLayout(new GridBagLayout());
GridBagConstraints g = new GridBagConstraints();
g.fill = GridBagConstraints.HORIZONTAL;
g.weightx = 1d;
Color customColor = new Color(225, 250, 250);
Color customColor2 = new Color(169, 169, 169);
text = new JLabel("\t\t\t\t\tthe quick brown fox jumps over the lazy dog\t\t\t\t");
text.setFont(new Font("Ariel", Font.BOLD, 19));
add(text, g);
g.gridy = 1; g.gridx = 0;
q = new JLabel("q");
q.setOpaque(true);
q.setBackground(customColor2);
q.setFont(new Font("Calibiri", Font.BOLD, 16));
add(q, g);
w = new JLabel("w");
w.setOpaque(true);
w.setBackground(customColor2);
w.setFont(new Font("Calibiri", Font.BOLD, 16));
g.gridx = 1;
add(w, g);
text2 = new JTextArea(" ");
text2.setBackground(customColor);
text2.setFont(new Font("Ariel", Font.BOLD, 16));
g.gridx = 0;
g.gridy = 9;
add(text2, g);
}
I am trying to make a Typing gui. My problem is with the formatting of (J)labels. I can't figure out if it's because of GridBagLayout
or something else. First Jlabel
for every value of y (i.e g.gridy
in this case) is wider than any other.