탭이있는 간단한 웹 브라우저에서 작업하고 있습니다. 나는 tabbedpane 아래에 텍스트 필드를 추가하는 데 많은 어려움을 겪고 있습니다. 정확하게 크롬에있는 것과 같습니다. 내가 지금까지 가지고있는 것들 Heires : public class Browser { private JFrame frame; 전용 JPanel panelTop; 비공개 JEditorPane 에디터. private JScrollPane 스크롤; private JTextField 필드. 개인 JButton 버튼; 개인 JButton 홈; 비공개 URL url; 비공개 JMenu 파일 = 새 JMenu ("파일"); 비공개 JMenuItem exit = 새 JMenuItem ("Exit"); private JMenuBar menuBar = 새 JMenuBar(); private ImageIcon nt = new ImageIcon ("./ 아이콘/newTab.jpg"); 개인 ImageIcon cl = 새 ImageIcon ("./ 아이콘/닫기.png"); 비공개 JButton newTab = 새 JButton (cl); 비공개 JTabbedPane tabbedPane = 새로운 JTabbedPane(); 개인 int tabCounter = 0; private Dimension dim = new Dimension (nt.getIconWidth() + 2, ) nt.getIconHeight() + 2); 공개 브라우저() { initComponents();JTextField를 JEditorPane 위에두고 JTabbedPane 아래에 JTextField를 가져올 수 있습니까?
frame = new JFrame();
frame.setTitle("TeslaNet Browser");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,600);
frame.setJMenuBar(menuBar);
menuBar.add(file);
file.add(exit);
exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
panelTop = new JPanel();
frame.add(BorderLayout.NORTH, panelTop);
panelTop.add(field);
panelTop.add(button);
panelTop.add(home);
panelTop.add(newTab);
newTab.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
initComponents();
}
});
newTab.setToolTipText("New Tab");
newTab.setPreferredSize(dim);
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
frame.add(topPanel);
topPanel.add(tabbedPane, BorderLayout.CENTER);
panelTop.add(scroll, BorderLayout.CENTER);
frame.setVisible(true);
}
private void initComponents()
{
try
{
url = new URL("http://www.reddit.com");
}
catch(MalformedURLException mal)
{
JOptionPane.showMessageDialog(null,mal);
}
try
{
editor = new JEditorPane(url);
editor.setEditable(false);
}
catch(IOException ioe)
{
JOptionPane.showMessageDialog(null,ioe);
}
scroll = new JScrollPane(editor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
field = new JTextField(14);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
field.setText(url.toString());
}
});
button = new JButton("Go");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
editor.setPage(field.getText());
}
catch(IOException ioe)
{
JOptionPane.showMessageDialog(null, ioe);
}
}
});
home = new JButton("Home");
home.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
url = new URL("http://www.thissongissick.com");
field.setText(url.toString());
}
catch(MalformedURLException mal)
{
JOptionPane.showMessageDialog(null,mal);
}
try
{
editor.setPage(field.getText());
}
catch(IOException ioe)
{
JOptionPane.showMessageDialog(null, ioe);
}
}
});
JPanel tab = new JPanel();
JButton closeButton = new JButton(nt);
closeButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tabbedPane.remove(tabbedPane.getTabCount()-1);
}
});
closeButton.setPreferredSize(dim);
closeButton.setToolTipText("Close");
JLabel tabLabel = new JLabel("Tab " + (++tabCounter));
System.out.print(tabbedPane.getSelectedIndex());
tab.setOpaque(false);
tab.add(tabLabel, BorderLayout.WEST);
tab.add(closeButton, BorderLayout.EAST);
tabbedPane.addTab(null, editor);
tabbedPane.setTabComponentAt(tabbedPane.getTabCount()-1, tab);
}
}
고마워요!
게시하시기 바랍니다 컴파일 가능한 예제를해야합니다. –
귀하의 문제는 거의 레이아웃 관리자와 관련되어 있으므로 개별 구성 요소가 아니라 귀하의 태그를 편집했습니다. – Pureferret
사용 된 다른 초기화 방법에 더하여 초기화를 추가했습니다 – intrigatory57