Total members 11890 |It is currently Tue Apr 23, 2024 8:10 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





This is a example of JToolBar usage where there is many buttons with images, where any one these button is pressed a new dialog forms is opened its is code is not listed here but the idea is clear. There is a connection to database object is passed to the constructor but you may remove in your case but it is used here because this bar is for database project. JTabbedPane object is added to JToolBar.
Attachment:
File comment: Screen-Shot of Tool-Bar
ToolBarImage.gif
ToolBarImage.gif [ 11.91 KiB | Viewed 4476 times ]

java code
class myToolbar extends JToolBar {

public myToolbar(final JTabbedPane Tabbed, final JFrame myMother, final Connection conn) {
// setLayout(null);

AddImag = new ImageIcon("icons/Add.png");

SearchImag = new ImageIcon("icons/Search.png");
ModifyImag = new ImageIcon("icons/Modify.png");
RemoveImag = new ImageIcon("icons/Remove.png");
BorrowImag = new ImageIcon("icons/Borrow.png");
ReturnImag = new ImageIcon("icons/Return.png");
ReportImag = new ImageIcon("icons/Report.png");


AddBut = new JButton("Add", AddImag);
SearchBut = new JButton("Search", SearchImag);
ModifyBut = new JButton("Modify", ModifyImag);
RemoveBut = new JButton("Remove", RemoveImag);
BorrowBut = new JButton("Borrow", BorrowImag);
ReturnBut = new JButton("Return", ReturnImag);
ReportBut = new JButton("Report", ReportImag);

AddBut.setAlignmentY(CENTER_ALIGNMENT);
SearchBut.setAlignmentY(CENTER_ALIGNMENT);
ModifyBut.setAlignmentY(CENTER_ALIGNMENT);
RemoveBut.setAlignmentY(CENTER_ALIGNMENT);
ReturnBut.setAlignmentY(CENTER_ALIGNMENT);
ReportBut.setAlignmentY(CENTER_ALIGNMENT);
add(AddBut);
add(SearchBut);
add(ModifyBut);
add(RemoveBut);
add(BorrowBut);
add(ReturnBut);
add(ReportBut);
AddBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {


switch (Tabbed.getSelectedIndex()) {
case 0:
((new VisitorPanel(conn, myMother))).show();
break;
case 1:
(new BookPanel(conn, myMother)).show();
break;
case 2:
(new AuthorPanel(conn, myMother)).show();
break;
case 3:
(new PublisherPanel(conn, myMother)).show();
break;
case 4:
(new BookStorePanel(conn, myMother)).show();
break;

default:
break;
}

}
});
SearchBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {


switch (Tabbed.getSelectedIndex()) {
case 0:
(new VisitorSearch(conn, myMother)).show();
break;
case 1:
(new BookSearch(conn, myMother)).show();
break;
case 2:
(new AuthorSearch(conn, myMother)).show();
break;
case 3:
(new PublisherSearch(conn, myMother)).show();
break;
case 4:
(new BookStoreSearch(conn, myMother)).show();
break;

default:
break;
}


}
});
ModifyBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {



switch (Tabbed.getSelectedIndex()) {
case 0:
(new VisitorModifyPanel(conn, myMother)).show();
break;
case 1:
(new BookModifyPanel(conn, myMother)).show();
break;
case 2:
(new AuthorModifyPanel(conn, myMother)).show();
break;
case 3:
(new PublisherModifyPanel(conn, myMother)).show();
break;
case 4:
(new BookStoreModifyPanel(conn, myMother)).show();
break;

default:
break;
}

}
});
RemoveBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {



switch (Tabbed.getSelectedIndex()) {
case 0:
(new VisitorRemovePanel(conn, myMother)).show();
break;
case 1:
(new BookRemovePanel(conn, myMother)).show();
break;
case 2:
(new AuthorRemovePanel(conn, myMother)).show();
break;
case 3:
(new PublisherRemovePanel(conn, myMother)).show();
break;
case 4:
(new BookStoreRemovePanel(conn, myMother)).show();
break;

default:
break;
}
}
});

ReturnBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});

ReportBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});

}
private JButton AddBut;
private JButton SearchBut;
private JButton ModifyBut;
private JButton RemoveBut;
private JButton BorrowBut;
private JButton ReturnBut;
private JButton ReportBut;
private Icon AddImag;
private Icon SearchImag;
private Icon ModifyImag;
private Icon RemoveImag;
private Icon BorrowImag;
private Icon ReturnImag;
private Icon ReportImag;
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : JToolBar usage example
 tt usage example     -  
 Usage of UL tag     -  
 Usage of sub tag     -  
 dir tag usage     -  
 dd tag usage     -  
 var tag usage     -  
 usage of ol tag     -  
 Usage of sup tag     -  
 Usage of ins tag     -  
 usage of kbd tag     -  



Topic Tags

Java Swing






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com