버튼이 수평으로 놓여 차례 차례로 수직으로 화면에 올리는 방법을 알려줍니다. 나는 SwingConstants.xxxx를 추가하려고 시도했다. 그런 다음 item.SwingConstants.xxx는 수평 정렬 오류가 발생했다. 어떤 도움을 주셔서 감사합니다.버튼을 정렬하는 방법
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class Class_GUI_4 extends JFrame {
private JTextField tf; // textfield
private JCheckBox b1; // button 1
private JCheckBox b2; // button2
public Class_GUI_4() {
super("TITLE");
setLayout(new FlowLayout());
tf = new JTextField("A testing Sentence", 20);
tf.setFont(new Font("Serif", Font.PLAIN, 14));
add(tf);
b1 = new JCheckBox("Bold");
b2 = new JCheckBox("Italic");
add(b1);
add(b2);
thehandler handler = new thehandler();
b1.addItemListener(handler);
b2.addItemListener(handler);
}
private class thehandler implements ItemListener {
@Override
public void itemStateChanged(ItemEvent event) {
Font font = null;
if (b1.isSelected() && b2.isSelected())
font = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
else if (b1.isSelected())
font = new Font("Serif", Font.BOLD, 14);
else if (b2.isSelected())
font = new Font("Serif", Font.ITALIC, 14);
else
font = new Font("Serif", Font.PLAIN, 14);
tf.setFont(font);
}
}
public static void main(String[] args) {
Class_GUI_4 gui = new Class_GUI_4();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setSize(200, 350);
gui.setVisible(true);
}
}
나는 모두를 시도하고 관찰 등 빠르고 신속한 대응을 위해 U 모두 감사합니다. 텍스트 필드의 크기를 줄이는 방법 (높이)을 알려주십시오. 전체 화면을 차지하고 두 개의 확인란을 사용하여 끝에는 거의 공간을 남기지 마십시오. 친절하게 스레드에 긍정적 인 점수를 남겨 둘 그래서 나는 주된 대답을 똑딱 거리고 난 후에 여러 개의 대답을 좋아할만큼 충분한 repo를 얻을 수있다. 다시 한번 감사드립니다 .... @ Braj –
마지막 옵션을 시도하고 요구 사항에 따라 높이를 백분율로 변경하십시오. – Braj