| | |
Subpanel problem
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 0
I am trying to create a class which could be a subpanel. It extends JPanel and implements AdjustmentListener. The JPanel is used here as a container and it keeps JLabels and JScrorrButtons layouted with gridBagLayout.
This class instantiated in application doesn't work, none of components (labels and scroolButtons) don't even show up.
what could be wrong with it... maybe it is the case of event handling?? any idaes?
This class instantiated in application doesn't work, none of components (labels and scroolButtons) don't even show up.
Java Syntax (Toggle Plain Text)
public class parameteManager extends JPanel implements AdjustmentListener{ public JPanel pane; public JScrollBar scrbF; public JScrollBar scrbA ; public JScrollBar scrbC ; public JTextField wartF ; public JTextField wartA ; public JTextField wartC ; public parameteManager(int a,int b,int c,int d,int e,int f,int g,int h,int i, int j,int k,int l,java.lang.String z) { scrbF = new JScrollBar(JScrollBar.HORIZONTAL, a, b, c, d); scrbA = new JScrollBar(JScrollBar.HORIZONTAL, e, f, g, h); scrbC = new JScrollBar(JScrollBar.HORIZONTAL, i, j, k, l); wartF = new JTextField (); wartA = new JTextField (); wartC = new JTextField (); pane=new JPanel(); pane.setSize(500,300); GridBagLayout gridbg = new GridBagLayout(); GridBagConstraints constr = new GridBagConstraints(); constr.insets=new Insets(2,2,2,2); pane.setLayout(gridbg); //adding components to the panel , to set all constraints needed for gridBagLayout buildConstraints function is used. buildConstraints(constr, 0, 0, 1, 1, 30, 2,3,0); constr.fill = GridBagConstraints.NONE; constr.anchor = GridBagConstraints.EAST; JLabel label1 = new JLabel("Faza:", JLabel.LEFT); gridbg.setConstraints(label1, constr); pane.add(label1); //amplituda //pokaz wart czestotl wartC.setEditable(false); wartC.setText(""+scrbC.getValue()); buildConstraints (constr,1,2,1,1,0,0,3,0); constr.fill= GridBagConstraints.HORIZONTAL; constr.anchor = GridBagConstraints.CENTER; gridbg.setConstraints(wartC, constr); pane.add(wartC); pane.setBorder(BorderFactory.createTitledBorder("Manager O"+z)); try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } } public void adjustmentValueChanged(AdjustmentEvent e) { Object source = e.getSource(); //scrbF scrbA scrbC - zrodlo zdarzenia if (source == scrbF) { int value=scrbF.getValue(); wartF.setText(""+value); } if (source == scrbA){ int value=scrbA.getValue(); wartA.setText(""+value/10); } if (source == scrbC){ int value=scrbC.getValue(); wartC.setText(""+value); } } private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy,int px, int py) { //gbc.insets = new Insets(5,5,3,5); gbc.gridx = gx; gbc.gridy = gy; gbc.gridwidth = gw; gbc.gridheight = gh; gbc.weightx = wx; gbc.weighty = wy; gbc.ipadx=px; gbc.ipady=py; } private void jbInit() throws Exception { } } //the applicaion that uses parameteManger class public class Chart extends JFrame implements AdjustmentListener{ parameteManager managerx,managery; //subpanels JPanel contentPane; public Chart(){ super ("Chart"); contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); //contentPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); managerx= new parameteManager(2,0,0,6,60,0,60,100,2,0,0,100,"X"); managery= new parameteManager(2,0,0,6,60,0,60,100,2,0,0,100,"Y"); contentPane.add(managerx); contentPane.add(managery); setContentPane(contentPane); setTitle("Chart"); try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } } public static void main(String[] args){ JFrame frame = new Lissajous1(); ExitWindow exit = new ExitWindow(); frame.addWindowListener(exit); frame.show(); } public void adjustmentValueChanged(AdjustmentEvent e) { Object source = e.getSource(); //scrbF scrbA scrbC - zrodlo zdarzenia if (source == managerx.scrbF) { int value=managerx.scrbF.getValue(); } if (source == managerx.scrbA){ int value=managerx.scrbA.getValue(); } if (source == managerx.scrbC){ int value=managerx.scrbC.getValue(); } } private void jbInit() throws Exception { this.setResizable(false); } }
what could be wrong with it... maybe it is the case of event handling?? any idaes?
•
•
Join Date: Mar 2004
Posts: 802
Reputation:
Solved Threads: 40
That's because "parameteManager" doesn't contain anything. "parameteManager" is a panel, that's what you're adding inside of "Chart". The panel is technically still blank, you must add your scrollbars and other panels to it first. Simply stated, add at the end of the "parameteManager" contructor.
Also, the size of the JFrame isn't being set properly, and with you calling jbInit() inside of Chart, you can't resize the frame and won't see the content anyway.
Java Syntax (Toggle Plain Text)
this.add(pane);
Also, the size of the JFrame isn't being set properly, and with you calling jbInit() inside of Chart, you can't resize the frame and won't see the content anyway.
![]() |
Similar Threads
- Problem with Windows Update and WinXP (Web Browsers)
- Installing Windows 98 On VMware. Floppy problem (Windows 95 / 98 / Me)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Problem with T720 (Cellphones, PDAs and Handheld Devices)
- Connection Problems (Networking Hardware Configuration)
- .htaccess mod_rewrite problem (Linux Servers and Apache)
Other Threads in the Java Forum
- Previous Thread: java 3d tutorials wanted!!!
- Next Thread: How to deativate minimize on JFrame
Views: 2093 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application applications arguments array arrays automation bank binary bluetooth chat class classes clear client code codesnippet component database db development dice draw ebook eclipse error event exception file formatingtextintooltipjava fractal game givemetehcodez graphics gui helpwithhomework html ide image infinite input integer invokingapacheantprogrammatically j2me jarfile java javaprojects jmf jni jpanel julia linux list loop map method methods mobile netbeans newbie number object openjavafx oracle parameter print problem program programming project recursion repositories scanner screen scrollbar server set size sms socket sort sorting sql sqlserver state storm string superclass swing swt test text-file threads time transfer tree windows





