자바 스윙 관련 기사를 많이 읽은 후 거의 눈이 어두워졌지만 여전히 패널을 사용할 수 없습니다.
2 개의 JLabel을 추가하면 EmptyBorder에 의해 정의 된 5px 패딩으로 왼쪽에 멋지게 정렬됩니다. 내가 예상대로 패딩에 추가 테두리의 ProgressBar를 추가 한 후 작동하지 않는 것으로 확인JPanel을 추가 한 후 JLabel이 잘못 위치했습니다.
, 내가 ProgressBar를 추가 한 더 패널을 추가했다. 진행 상황은 좋아 보이지만 모든 레이블이 옮겨졌습니다.
그리고 마지막으로는 다음과 같이 (RED 배경 디버깅을위한, JPanel을 그리는 방식을 볼 수 있습니다) :
Question1 : 방법이 문제를 해결하는가?
질문 2 : 스윙을위한 표준 접근법은 다른 패널과 함께 다른 패널과 패널을 배치하는 것입니다. 원하는 패널을 얻기 위해서입니까?
출처 :
public class AppInitProgressDialog {
private static final int VIEW_PADDING_VAL = 5;
private static final Border viewPaddingBorder = new EmptyBorder(VIEW_PADDING_VAL, VIEW_PADDING_VAL, VIEW_PADDING_VAL, VIEW_PADDING_VAL);
private JPanel view; // Dialog view
private JPanel panel;
private JPanel progressPanel;
private JLabel title;
private JLabel progressDesc;
private JProgressBar progressBar;
private void initPanel(int w, int h) {
view = new JPanel();
view.setBorder(BorderFactory.createRaisedSoftBevelBorder());
view.setBackground(Color.LIGHT_GRAY);
view.setSize(w, h);
view.setLayout(new BorderLayout());
panel = new JPanel();
panel.setBorder(viewPaddingBorder);
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
//panel.setLayout(new SpringLayout());
panel.setOpaque(false);
JFrame parent = AppContext.getMe().getAppWindow().getFrame();
int posx = (parent.getWidth() - w)/2;
int posy = (parent.getHeight() - h)/2;
view.add(panel, BorderLayout.CENTER);
view.setLocation(posx, posy);
}
private void initTitle() {
title = new JLabel("Progress title");
title.setAlignmentX(JComponent.LEFT_ALIGNMENT);
panel.add(title);
}
private void initProgress() {
progressPanel = new JPanel(new BorderLayout());
progressPanel.setBackground(Color.LIGHT_GRAY);
progressPanel.setBorder(new EmptyBorder(15, 30, 15, 30));
progressPanel.setBackground(Color.RED);
progressBar = new JProgressBar(0, 10000);
progressBar.setStringPainted(true);
progressBar.setAlignmentX(JComponent.LEFT_ALIGNMENT);
progressPanel.add(progressBar);
panel.add(progressPanel);
progressDesc = new JLabel("Progress description");
panel.add(progressDesc);
}
public AppInitProgressDialog() {
initPanel(400, 100);
initTitle();
initProgress();
}
public JComponent getView() {
return view;
}
}
내가 질문을 편집하고 제목에 원래의 질문에 관련이 미래 질문 (3)을 제거하는 것이 좋습니다. – sm4