Results 1 to 8 of 8
Thread: JButton click problem
- 06-08-2010, 07:25 AM #1
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
JButton click problem
Hi, here again :). I have problem with JButton.
Theses is what I expect to happen when I click JButton(VIEW):
Here is the code:1. Check JCombo box' selectedindex.
2. resize appropriate panel for the selected index in JCombo box
3. Do some SELECT query.
4. Show to JTable and resize JTable.
Thanks for always helping me,Java Code://[b]activeTable() - check the Jcombobox' index and resize the right panel and hide other panel[/b] private void [b]activeTable()[/b]{ if(cmbTables.getSelectedIndex() == 0) { pnlStocks.setVisible(true); pnlStocks.setEnabled(true); pnlStocks.setSize(670, 220); pnlStocks.setLocation(6, 97); } else { pnlStocks.setVisible(false); pnlStocks.setEnabled(false); pnlStocks.setSize(1, 1); pnlStocks.setLocation(0, 1); } if(cmbTables.getSelectedIndex() == 1) { pnlReq.setVisible(true); pnlReq.setEnabled(true); pnlReq.setSize(670, 220); pnlReq.setLocation(6, 97); } else { pnlReq.setVisible(false); pnlReq.setEnabled(false); pnlReq.setSize(1, 1); pnlReq.setLocation(0, 1); } } //[b]JButton click event[/b] private void [b]btnViewClicked(java.awt.event.ActionEvent evt)[/b] { String myQuery=null; [i]activeTable();[/i] switch (cmbTables.getSelectedIndex()) { case 0: [b][i]//do something. //If I choose this in JCombo and click this button everything works fine[/i][/b] break; case 1: [b][i]//If I choose this in JCombo and click this button then the panel did not resize //but on the second time that I click it the panel will show..[/i][/b] myQuery = "SELECT * FROM mytable"; String[] reqHeader = {"TITLE#1", "TITLE#2", "TITLE#3", "TITLE#4"}; MaterialsQuery.selectMat(myQuery, tbl_Mat, reqHeader); resizeReqTable(); break; } }
gejeLast edited by mine0926; 06-08-2010 at 07:28 AM.
-
I'm not sure what your problem is based on the code as shown, but perhaps you need to do your database work in a background thread such as by using a SwingWorker. If this doesn't help you, then consider creating a very small program (without netbeans generated code if possible) that show your problem.
As an aside, you will likely find that by using an appropriate layout manager or combination of managers and calling pack() on your GUI, you will have an easier time of having your app resize as appropriate.
Much luck!
- 06-09-2010, 05:42 AM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
I copy the codes(except to the generated codes) and paste it in notepad then run the program through command prompt. Everything works as expected. You think I am having problem with Layouts and grouping the netbeans generated?
Thanks for the reply and for pointing me in SwingWorker:D.
- 06-09-2010, 08:08 AM #4
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Everything is fine now and working as expected. I just change JFrame and JPanels layout from Free Design to Null Layout.
Thanks. :)
geje
-
- 06-10-2010, 08:16 AM #6
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Hi,
pardon, I misunderstood your answer. I still use Null Layout in Design mode, should I put it back in Free Design?. But in code I use some layout manegers and add JPanels inside JPanels to set components alignment.
Right now I am having problem aligning it but I will solve it myself first then if I cant really find how to do things then I will post back here.
Thanks for pointing me.
geje
-
I recommend that you use one or more of the user-friendly layout managers in one or more nested JPanels such as BorderLayout, BoxLayout, FlowLayout, GridLayout, and if necessary, GridBagLayout.
- 06-11-2010, 03:00 AM #8
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Thats what I did... or am I getting thing the other way?
At first I did not add pnlStocks(JPanel) and pnlReq(JPanel) in pnlSecnd.
Java Code:public frmMaterials() { this.setLayout(new BorderLayout()); this.add(pnlFirst, BorderLayout.PAGE_START); this.add(pnlSecnd, BorderLayout.CENTER); this.add(jScrollPane1, BorderLayout.PAGE_END); pnlFirst.setLayout(new GridLayout(0,2)); pnlFirst.add(jPanel1); pnlFirst.add(jPanel2); pnlSecnd.setLayout(new BorderLayout()); pnlSecnd.add(jPanel3,BorderLayout.LINE_END); pnlStocks.setVisible(false); pnlReq.setVisible(false); }
then in button click
Java Code:activeTable(); ...
activeTable() method remove and add JPanels.
Thanks,Java Code:private void activeTable(){ if(cmbTables.getSelectedIndex() == 0) { pnlStocks.setVisible(true); pnlSecnd.add(pnlStocks, BorderLayout.LINE_START); } else { pnlStocks.setVisible(false); pnlSecnd.remove(pnlStocks); } if(cmbTables.getSelectedIndex() == 1) { pnlReq.setVisible(true); pnlSecnd.add(pnlReq, BorderLayout.LINE_START); } else { pnlReq.setVisible(false); pnlSecnd.remove(pnlReq); } }
geje
Similar Threads
-
Problem with click to move ball algorithm
By Laythe in forum Java AppletsReplies: 1Last Post: 12-19-2009, 12:00 AM -
JButton Problem
By wassim in forum AWT / SwingReplies: 6Last Post: 02-18-2009, 10:29 PM -
Problem in mouse click n repaint
By Preethi in forum New To JavaReplies: 4Last Post: 07-04-2008, 11:16 AM -
how to click a jbutton and open an url
By katie in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 10:44 PM -
Problem with JButton
By Marcus in forum AWT / SwingReplies: 1Last Post: 07-05-2007, 05:56 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks