Switch to full style
Graphics and animation Java code examples
Post a reply

JToolBar usage example

Thu Jan 31, 2013 10:58 pm

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.
ToolBarImage.gif
Screen-Shot of Tool-Bar
ToolBarImage.gif (11.91 KiB) Viewed 4649 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;
}




Post a reply
  Related Posts  to : JToolBar usage example
 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     -  
 tt usage example     -  
 Usage of UL tag     -  
 Usage of sub tag     -  

Topic Tags

Java Swing