두 개의 splitPanel과 메뉴 모음이 포함 된 대화 상자를 만들려고합니다. 두 splitPanel 모두 jlist를 포함합니다.jmenubar 옆에 흰색 영역이 나타나는 이유는 무엇입니까?
하지만 내 코드를 실행할 때 메뉴 막대 옆에 흰색 영역이 표시됩니다. 아래 그림에서 흰색 영역은 옆에 생성되고으로 구성됩니다.
public class HistList extends JPanel {
JTable table = new JTable();
JMenuItem remove = new JMenuItem("Remove");
JScrollPane scrollPane = new JScrollPane();
MyTableModel model = new MyTableModel();
HistList() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
String[] title = {" ", "Time", "Name", "Location"};
Object[][] data = {
{false, "01:22:16", "Google", "http://www.google.com"},
{false, "01:22:16", "Yahoo - login", "https://login.yahoo.com/?.src=ym&.intl=us&.lang=en-US&.done=https%3a//mail.yahoo.com"},
{false, "01:22:29", "Oracle | Integrated Cloud Applications and Platform Services", "https://www.oracle.com/index.html"}
};
for (int i = 0; i < data.length; i++) {
model.addRow(data[i]);
}
this.table = new JTable(model);
this.table.setShowGrid(false);
this.scrollPane = new JScrollPane(this.table);
Dimension size = new Dimension(510, 380);
this.scrollPane.setPreferredSize(size);
this.scrollPane.getViewport().setBackground(Color.WHITE);
JTextField name = new JTextField();
name.setPreferredSize(new Dimension(scrollPane.getWidth(), 25));
JTextField locationText = new JTextField();
locationText.setPreferredSize(new Dimension(scrollPane.getWidth(), 25));
JPanel textPane = new JPanel();
JLabel nameLabel = new JLabel("Name:");
JPanel textPane1 = new JPanel();
textPane1.setLayout(new BoxLayout(textPane1, BoxLayout.X_AXIS));
textPane1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
textPane1.add(Box.createHorizontalGlue());
textPane1.add(nameLabel);
textPane1.add(Box.createRigidArea(new Dimension(21, 0)));
textPane1.add(name);
JLabel locationLabel = new JLabel("Location:");
JPanel textPane2 = new JPanel();
textPane2.setLayout(new BoxLayout(textPane2, BoxLayout.X_AXIS));
textPane2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
textPane2.add(Box.createHorizontalGlue());
textPane2.add(locationLabel);
textPane2.add(Box.createRigidArea(new Dimension(5, 0)));
textPane2.add(locationText);
textPane.setLayout(new BoxLayout(textPane, BoxLayout.Y_AXIS));
textPane.setBorder(BorderFactory.createEmptyBorder(0, 2, 2, 2));
textPane.add(Box.createVerticalGlue());
textPane.add(textPane1);
textPane.add(Box.createRigidArea(new Dimension(0, 5)));
textPane.add(textPane2);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
contentPane.add(scrollPane);
contentPane.setBorder(BorderFactory.createEmptyBorder(0, 2, 2, 2));
contentPane.add(Box.createVerticalGlue());
contentPane.add(Box.createRigidArea(new Dimension(0, 5)));
contentPane.add(textPane);
JPanel pane = new JPanel(new BorderLayout());
pane.setBorder(BorderFactory.createEmptyBorder(15, 0, 0, 0));
pane.setBackground(Color.WHITE);
String[] dates = {"12/15/2016", "12/30/2016"};
JList list;
list = new JList(dates);
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
JLabel label = new JLabel("Browsing Date");
pane.add(label, BorderLayout.NORTH);
pane.add(list, BorderLayout.WEST);
pane.setPreferredSize(new Dimension(150, 380));
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, pane, contentPane);
JMenuBar organize = new JMenuBar();
organize.setOpaque(true);
organize.setBackground(getBackground());
JMenu menu = new JMenu("Organize");
menu.add(remove);
remove.setEnabled(false);
menu.setOpaque(true);
menu.setBackground(getBackground());
menu.setIcon(new ImageIcon(Hello.class.getResource("/rsz_todo-512.png")));
organize.add(menu);
JPanel finale = new JPanel(new BorderLayout());
finale.setOpaque(true);
finale.add(organize,BorderLayout.NORTH);
finale.add(splitPane,BorderLayout.CENTER);
setOpaque(true);
add(finale);
}
나는이 흰색 영역을 만드는 것을 알아낼 수 없습니다 :
다음은 코드 내 일부입니다. 나는이 섹션에서 아주 새로운 것이다. 누구든지 나를 고칠 수 있도록 도와 주시겠습니까? 내 어리석은 질문을 용서해주세요. 미리 감사드립니다. 난 내 코드를 실행하면
1) 더 나은 도움을 받으려면 [MCVE] 또는 [Short, Self Contained, Correct Example] (http://www.sscce.org/)를 게시하십시오. 2)'finale.add (organize, BorderLayout.NORTH);'setJMenuBar (..)'를 사용하지 않는 이유는 무엇입니까? 3) 모든'setBackground (..)'호출은 무엇입니까? 이것은 PLAF에서 처리해야합니다. –
제안을 주셔서 감사합니다. 지금 내 전체 코드를 게시했습니다. – IAmBlake
* "전체 코드"* 제안하지 않았으며 어떠한 경우에도 전체 코드가 아닙니다 (가져 오기가 누락되어있어 패널을 화면에 표시하는 기본 방법이 없음).). 링크를 제공 할 때 * 읽으십시오. –