?
Solved

adding combobox in netbeans jtable

Posted on 2008-10-19
5
Medium Priority
?
7,847 Views
Last Modified: 2013-12-14
hello,
i m using netbeans 6.0.i have a panel,on that panel i hv a scrollpane,on that scrollpane i have dragged n dropprd a jtable.i want to use a combobox in one of the ells and button in another cell.how i can do that?
thnx
0
Comment
Question by:mithunda5011
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:manuel_m
ID: 22751911
Make sure you have read the sun tutorial. There is a part of using JTable. There is also an example of adding a combobox to a column.
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#combobox

For adding a JButton to a cell you can also look at the solution at http://www.experts-exchange.com/Programming/Languages/Java/Q_22883043.html

If you have any problems regarding to this do not hesitate to post your question.

manuel
0
 

Author Comment

by:mithunda5011
ID: 22751933
thnx, but netbeans jtable has some different structure.it is not that simple jtable
0
 
LVL 6

Expert Comment

by:manuel_m
ID: 22751970
You can add the code in a separate init code block.
In your code there is a method called initComponents(); right?
After this method call you can add another method call. For example init();

And add a new method in your code where you add the code for the table.

Now you have added the code to your table.
private void init() {
        TableColumn comboboxColumn = jTable1.getColumnModel().getColumn(1);
        JComboBox comboBox = new JComboBox();
        comboBox.addItem("Snowboarding");
        comboBox.addItem("Rowing");
        comboBox.addItem("Chasing toddlers");
        comboBox.addItem("Speed reading");
        comboBox.addItem("Teaching high school");
        comboBox.addItem("None");
        comboboxColumn.setCellEditor(new DefaultCellEditor(comboBox));
 // ... etc.
}

Open in new window

1
 

Author Comment

by:mithunda5011
ID: 22752054
exellent....i hv added combobox...using the same coding i am unable to add button in another cell...

TableColumn comboboxColumn_new = jTable1.getColumnModel().getColumn(2);
        JButton jbutton = new JButton("add");
       
        comboboxColumn_new.setCellEditor(new DefaultCellEditor(jbutton));

it is giving error at DefaultCellEditor
0
 
LVL 6

Accepted Solution

by:
manuel_m earned 2000 total points
ID: 22752209
You have to create a renderer and an editor for this cell to add a jbutton to it.
As I have posted in my first post there you will find a solution. For example at this site http://www.codeguru.com/java/articles/129.shtml
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question