怎么在Java中添加Toolbar控件,且控件中有图案
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test0630Toolbar {
public static void main(String[] args) {
JFrame frame = new JFrame("JToolBar");
JToolBar jToolBar = new JToolBar("JToolBar");
JButton open =
new JButton("Open", new ImageIcon(Test0630Toolbar.class
.getResource("images/Open16.gif")));
jToolBar.add(open);
final JTextArea textArea = new JTextArea(5, 30);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea.append("open button clicked.\n");
}
});
frame.add(jToolBar, BorderLayout.PAGE_START);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
import java.awt.event.*;
import javax.swing.*;
public class Test0630Toolbar {
public static void main(String[] args) {
JFrame frame = new JFrame("JToolBar");
JToolBar jToolBar = new JToolBar("JToolBar");
JButton open =
new JButton("Open", new ImageIcon(Test0630Toolbar.class
.getResource("images/Open16.gif")));
jToolBar.add(open);
final JTextArea textArea = new JTextArea(5, 30);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea.append("open button clicked.\n");
}
});
frame.add(jToolBar, BorderLayout.PAGE_START);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询