이 인터페이스를 수정하는 데 도움을 주시면 감사하겠습니다. 난 그냥 GridBagLayout을 학습 시작하고 난 GridBagLayout에를 사용하여 그려 인터페이스()GridBagLayout을 사용하여이보기를 수정하는 방법
|-----------------------------------------------|
| Playing File: name of the file | //This JLabel should cover the entire space
|-----------------------------------------------|
| 00:00:00 ----#---------------------- 00:00:00 | //This has on the left and on the right side two labels and in the middle a JSpinner
|-----------------------------------------------|
| [Open] [Play] [Pause] [Rewind] [Save] | //This line contains 5 buttons
|-----------------------------------------------|
는 첨부 파일에 작업 예를
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingUtilities;
public class Sample extends JPanel
{
private JLabel labelFileName = new JLabel("Playing File:");
private JLabel labelTimeCounter = new JLabel("00:00:00");
private JLabel labelDuration = new JLabel("00:00:00");
private JButton buttonOpen = new JButton(" Open ");
private JButton buttonPlay = new JButton(" Play ");
private JButton buttonPause = new JButton(" Pause ");
private JButton buttonRewind = new JButton(" Rewind ");
private JButton buttonSave = new JButton(" Save ");
private JSlider sliderTime = new JSlider();
GridBagConstraints constraints = new GridBagConstraints();
public Sample()
{
setLayout(new GridBagLayout());
constraints.insets = new Insets(5, 5, 5, 5);
sliderTime.setValue(0);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 5;
constraints.fill = GridBagConstraints.HORIZONTAL;
add(labelFileName, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 1;
add(labelTimeCounter, constraints);
constraints.gridx = 1;
constraints.gridy = 1;
constraints.gridwidth = 3;
add(sliderTime, constraints);
constraints.gridx = 4;
constraints.gridy = 1;
constraints.gridwidth = 1;
add(labelDuration, constraints);
JPanel panelButtons = new JPanel(new FlowLayout(FlowLayout.LEFT, 25, 5));
panelButtons.add(buttonOpen);
panelButtons.add(buttonPlay);
panelButtons.add(buttonPause);
panelButtons.add(buttonRewind);
panelButtons.add(buttonSave);
constraints.gridx = 0;
constraints.gridy = 2;
add(panelButtons, constraints);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
runApp();
}
});
}
public static void runApp()
{
JFrame frame = new JFrame("Frame");
frame.setVisible(true);
frame.setSize(800, 200);
frame.add(new Sample());
frame.setDefaultCloseOperation
}
}
감사
을 찾아주세요을 구현할 수있는 방법을 알아낼 할
레이아웃을 디버깅 할 수있는 기능이 있으면 좋을 것입니다. 그것 이외의 :'sliderTime'은 너비가 3이 아니라 2가되어야합니다.'panelButtons'는 1이 아닌 너비가 5 여야합니다. 또한 두번째 열에 대한 가중치를 양수로 설정하려고합니다. – Ordous
'frame.setDefaultCloseOperation'을 잊지 마세요. 사람들이 mcve에서 그것을 잊어 버릴 때 참을 수 없습니다. 그것을 추가하는 것을 잊어 버린 경우, 많은 시간 동안 백 만개의 백그라운드 프로그램을 테스트하게 될 것입니다 :-) –
@peeskillet 편집 됨 : – QGA