Article View: borland.public.jbuilder.java.swing
Article #354Re: Extending JPanel - solved it
From: Magnus
Date: Thu, 01 Sep 2005 23:16
Date: Thu, 01 Sep 2005 23:16
95 lines
4421 bytes
4421 bytes
It was as simple as take this line out!
// ohmsLawPanel.setLayout(gridLayout1);
Magnus wrote:
> Hi,
>
> I want to build an application for set of calculators, about 20, (i.e.
> formulas where the user enters value, click calculate, and get the answer).
>
> My plan is to create a frame with a selection list to the left (in a
> JPanel) and a JPanel (cardlayout) to the right showing the formula
> selected in the list.
>
> Having worked with JB and cardlayout, Design mode gets really slow when
> a lot of labels and fields are entered. So my thought was to create a
> class per formula and extend JPanel and the only code in "main" would be
> to show the right panel with
>
> cardLayout1.show(jPanel2,"formula1Panel"); // jPanel2 is my cardlayout
> panel
>
> It works to a part. I create my formula1 class and set the Layout to
> GridBagLayout. It all looks good in design.
> In main (to test before I create my showRightFormula method) I try to
> just display the right panel with code as above, right after call to
> jbInit(). The panel shows empty.
>
> When I in design mode for "main" set different Layout managers, they
> override my formula1-class layout and displays as it feels like.
>
> What to do?
>
> --- Code ---
>
> // main
> JPanel jPanel1 = new JPanel(); // where to put list
> JScrollPane jScrollPane1 = new JScrollPane();
> JList calcSelectjList = new JList();
> GridBagLayout gridBagLayout1 = new GridBagLayout();
> JPanel jPanel2 = new JPanel(); // cardlayout panel
> CardLayout cardLayout1 = new CardLayout();
> formula1 ohmsLawPanel = new formula1();
> JPanel emptyPanel = new JPanel(); // to show when no selection
>
> //cosntructor
> try {
> setDefaultCloseOperation(EXIT_ON_CLOSE);
> jbInit();
> calcSelectjList.setListData(calculators);
> cardLayout1.show(jPanel2,"ohmsLawPanel");
> } catch (Exception exception) {
> exception.printStackTrace();
> }
>
> // my extended class
>
> class fomula1 extends JPanel {
>
> JTextField jTextField1 = new JTextField();
> JLabel jLabel2 = new JLabel();
> JLabel jLabel3 = new JLabel();
> JButton jButton1 = new JButton();
> GridBagLayout gridBagLayout1 = new GridBagLayout();
>
> public formula1() {
> try {
> jbInit();
> } catch (Exception ex) {
> ex.printStackTrace();
> }
> }
>
> public void paintComponent(Graphics g) {
> super.paintComponent(g);
> }
>
> private void jbInit() throws Exception {
> ...
> jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 20));
> jLabel1.setText("=");
> jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
> jLabel3.setText("*");
>
> jButton1.setMaximumSize(new Dimension(80, 30));
> jButton1.setMinimumSize(new Dimension(80, 30));
> jButton1.setPreferredSize(new Dimension(80, 30));
>
> jButton1.setText("Reset");
> ...
> this.add(jButton1, new GridBagConstraints(3, 2, 2, 1, 0.0, 0.0
> , GridBagConstraints.CENTER,
> GridBagConstraints.NONE,
> new Insets(13, 10, 18, 23), 20, 0));
> }
Technical Details
Message-ID:
<43178b9e@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<431741ee@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,5448ef0c9310d5df X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 01 Sep 2005 19:16:34 -0400 From: Magnus <magnus_bjorkman@iwon.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en, sv MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: Extending JPanel - solved it References: <431741ee@newsgroups.borland.com> In-Reply-To: <431741ee@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 65.40.194.165 Message-ID: <43178b9e@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1125616542 65.40.194.165 (1 Sep 2005 16:15:42 -0700) Lines: 95 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail