Sir, i have used two JButtons(Next,Previous) to perform actions. In a JTable, before clicking JButtons there is my 1st result. once i clicked the Next JButton then it show me the 2nd results in a JTable, and again clicking Next, it shows the 3rd result in JTable.
Same thing applies to Previous JButton also, once i clicked Previous then it shows me the 2nd results in JTable and again cicking for the 2nd time the previous JButton it shows me the 1st table. But it performs for only one time.

Again i tried to click the JButtons but it does not shows me the results.Actually i could not able to use the "clickCount" variable properly. what to do i donot understand. please give me some suggestion regarding this.....

Thank you in advance...

could u please tell how you add jbutton in jtable

Sir, i have used two JButtons(Next,Previous) to perform actions. In a JTable, before clicking JButtons there is my 1st result. once i clicked the Next JButton then it show me the 2nd results in a JTable, and again clicking Next, it shows the 3rd result in JTable.
Same thing applies to Previous JButton also, once i clicked Previous then it shows me the 2nd results in JTable and again cicking for the 2nd time the previous JButton it shows me the 1st table. But it performs for only one time.

Again i tried to click the JButtons but it does not shows me the results.Actually i could not able to use the "clickCount" variable properly. what to do i donot understand. please give me some suggestion regarding this.....

Thank you in advance...

Could u pls tell me how u add button in jtable

don't worry about that JTable is most Completed JCOmponents but works as you want or need

First of all thank you for your reply.. and next time sorry sir, i have not explained you properly my problem. So, i have a JPanel in a JFrame and in that JPanel i have added one scrollpane (which contains the JTable) and nextly i have added two JButtons(Next,Previous) to the right and left of the JPanel using Layout.

Now i need to perform the actions for the JButtons accordingly. When i click the JButtons then it must fetch the data from the Database and display the results in the JTable, but i could able to perform for 1 time only.

Probably, now i could explain you something. Sorry for my incomplete information i have provided earlier...

Thank you.

for this one exist only one FIX (basic WorksAround)

1/ inside ActionPerformed setEnabled(false); for this JButton
(if you want to repeat this action again in future)
2/ if done all needed steps enable it
3/ on Error (from your Methods) enable it again
4/ for this Action use only finally block (try - catch - finally)

Sorry sir. i did not get it what you have explained. Can you please give some more suggestion and explain further regarding this....

Thanks again.

myButton.setEnabled(false);

or setVisible(false);

Sir i have tried but it does not display anything. How to use "setEnable(boolean)" method. I am still cannot able to apply.

How it switches between JTables to display different datas.
thanks for your reply.

Hi sumprit.
What exactly are you having difficulty with? You need a method that retrieves and displays the right set of results. You need an instance variable (ie not declared within any method) that keeps track of which results to display (clickCount?). You need action listeners for the buttons that increment/decrement the results counter and call the method to display the right results. Which part is the problem?
And please don't call me "sir" :-)

ok! thanks for your response. Let me explain my problem. i have a database table maintaining values in time basis. first i need to show values of 8 hours in JTable and then next 8 hours and so on....

now first it will display first 8 hours values. Then after clicking Next it must show next 8 hours values in the same JTable and again clicking on it must show the next 8 hours and so on.

Again when i click previous then it must display the previous 8 hours values from the current 8 hours which is in display. Can you provide me some suggestion....

Thanks

OK, that's what I thought. Please read my previous post again - that's an outline of what you need, and here's some pseudocode to get you started.

public int firstHour = 1;

public void display8Hours() {
// put 8 hours starting with firstHour into the table
...

// in nextButton's ActionListener
// add 8 to firstHour
// call display8Hours

Thank you. i did like this as u suggest. But i can switch back and forth for 1 time only. if i click Next button then it shows me the required result and similarly i can perform the Previous button operation also.

but my main problem is that it performs for only 1 time. i have problem in switching the JTable values. please suggest some more information.

Sorry, I don't understand the question. What exactly happens if you click next twice?

ok!actually i cannot able to perform operation that when clicking JButton how to switch between the JTable values. I have use d3 methods current8hour,next8hour and next16hour. i have used

first above JButton actionperformed method i have displayed the current8hour values... then i displayed in actionperformed method thes lines....

//int clickCount=0
//actionPerformed(){
clickCount++;
//if(clickCount%2!=0){
//do next8hours.....calc
// }else{
//do next16hours...calc
}//

the same applied for Previous Button also. Now i can switch between the JTables if i click them properly means one after another. After 1st time clicking Next and then again clicking Next it gives me in proper way the values.... but when i click in random order means once clicking Next button i clicked Previous button then it gives wrong values.
I know my way of doing is wrong because i have used (clickCount%2!=0)...

Please give me some suggestion....

Aha! It looks like the problem is in your clickCount%2 logic - it's not sufficient to distinguish between going forwards and going backwards.
This isn't the best way to do things but it should work...
clickCount++ in next, clickCount-- in previous button. Then do the if test like this
if (clickCount ==1) doCurrent8Hours
else if (clickCount ==2) do next8
else if (clickCount ==3) do the 8 after that
Also
if (ClickCount == 1) disable previous button - there are no previous hours
else enable previous button
... and similarly for the next button - disable it when you are at the last 8 hours.
Yoiu can enable/disable buttons (like mKorbel said) with
myButton.setEnabled(true); and myButton.setEnabled(false);

ps: I have to go offline for a few days starting in about 1 hour

Thank you. thank you very much. Now i get the idea and i will continue further.... This greatly helped me...

you are really good. Thanks for giving your valuable time.

Good luck
J

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.