Monday 15 August 2011

java - How to implement a JPanel that shows/hide content depending on its width? -


I am trying to apply a JPanel which displays more or less information based on available size.

In fact, the idea is such a default content:

image Enter details here

This can be reduced when the space is reduced:

 Image Description Here

My code is such as:

  import net.miginfocom.swing.MigLayout; Import javax.swing *; Class Panel Dimos JPanel {Private Final JLabel Title = New JLab (); Private Final JLab Counter 1 = New JLABEL ("00"); Private Final JLAB counter 1 label = new JLab (); Private Final JLab Counter 2 = New JLABEL ("00"); Private Final JLab counter 2 label = new JLab (); / ** * An new ABS App Cadre message blocks the panel panel * / Public panelmedom () {this.SsetOpaque (wrong); InitGUI (); } Private Final Zero initGUI () {// 1Â °) Final Miglaut migLayout = New MigLayout ("fillx, hidemode 2, debug", "[growprio 0] []" // defined 4 columns); SetLayout (migLayout); // 2 °) // add (title, "spanx"); Plus (counter 1, "newline"); Add (counter1Label); (Counter2); Add (counter2Label); } Public static zero main (string [] Args) {Final JFrame jFrame = New JFrame ("test 4"); JFrame.getContentPane (). SetLayout (new megallout ("Phillix, debug")); Final panel dimo item 1 = new panel demo (); Item1.title.setText ("Element 1"); Item1.counter1Label.setText ("First LBL"); Item1.counter2Label.setText ("Second LBL"); JFrame.getContentPane (). Add (item 1, "groupex, gpx 110"); Final panelDimo item 2 = new paneldomain (); Item2.title.setText ("Element 2"); Item2.counter1Label.setText ("First LBL"); Item2.counter2Label.setText ("Second LBL"); JFrame.getContentPane (). Add (item 2, "groupux, gpx100"); JFrame.pack (); JFrame.setVisible (true); }}   

I tried to hide / hide my secondary labels, but I was not successful, tried to add a component listener and override component risized ().

Is anyone aware of implementing such behavior that increases preferences of well-being with Migelout increases?

Update1: I was wondering ... what if I set the minimum 1 + 1 label counter, and the maximum size for counter 2 + label 2 and then the operations Will the mechanization work to change the shape and change the size of the minimum or its maximum?

How about:

  public static JPNL panel (string ) {Jepynel Panel = New Zygel (New Miglite ("Inset 0, Rap 4, Philix, Debug", "[] [] 200 Shrink) [200 Decrease, Increase 200]"); Panel.add (new jlabel (name), "span x 4"); Panel.add (new JLab ("00")); Panel.ed (new jlabel ("first lbl"); Panel.add (new jlab ("01"); Panel.add (new JLABEL ("second LLBL")); Return panel; } Public static zero main (string [] algs) {Jepynel panel = new zipeline (new mangleout ("Inset 10, gap 10, Philix, debug")); Panel.add (panel ("element 1"), "w (50% - 15)!"); Panel.add (panel ("Element 2"), "w (50% - 15)!"); Jeffre Frame = New Gefram (); Frame.setContentPane (panel); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.pack (); Frame.setVisible (true); }   

I had difficulty in shaping the two main columns equally; I had to do by setting the width on the components instead of columns. I'm not sure why this is so.

No comments:

Post a Comment