Thursday, 15 May 2014

java - Putting 2 jpanels in borderlayout -


I'm trying to add 2 zpn to the border. It is such that, a japnil-shaped pen will be of 1 (600,600) and the second one will have a pen 2 (200,600). I'm hoping to pack them that a large number will be on the left side and the other one is correct. I'm setting the shape of each JPIN, but it seems that both of them overlap the entire space and kind on each other

I am a complete newbie here and I do not know what is going wrong. Any help is appreciated Jeffrey Frame = New Jeffrey ("Simple Graph"); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.setLayout (new border layout ()); Int pane1_width = FRAME_WIDTH-200; // 800-200 pen 1 myPlots = new pen 1 (graph_panel_size, frames_HEIGHT);
frame.ed (MyPlay); Pane2 simpleInfo = new pen2 (200, frame_height); Frame.add (simpleInfo); Frame.pack (); Frame.setSize (FRAME_WIDTH, FRAME_HEIGHT); Frame.setResizable (wrong); Frame.SsetVisible (true);

This is a base frame class for

public page 2 (integer width, integer height) {/ this.setSize (width, height) ; Border blackline = borderfacture Siquette titledirector ("Ola"); This.setBorder (Blackline);

The other panel has a similar constructor but both genpelles overlap each other and I can not keep them separately

The problem is that you are calling setSize () . When using the setSize / setBounds / setLocation , it is completely useless when using LayoutManager '(which you should always have)).

Additionnaly, calling SetPreferredSize () / setMinimumSize / setMaximumSize is not recommended and may be reversed.

Either a good reason for the size given to your component (because you're doing custom painting, for example), then you should override the getPreferredSize Or you just do not need to do anything, and use only the appropriate layout manager .

You can also

.BorderLayout; Import java.awt.color; Import java.awt.Dimension; Import java.awt.Graphics; Import javax.swing.JFrame; Import javax.swing.JPanel; Import javax.swing.SwingUtilities; Public Class TestCustomPainting {Private Static Category MyTriangle JPanel {Private Finals provides width width; Private Final In Height; Public MyTriangle (integer width, integer height) {this.width = width; This.height = Height; } @ Override Get Public Dimensions First Size () {Return New Dimension (Width, Height); } @ Override Protected Zero Paint Comonant (Graphics G) {SuperPaintConant (G); G.setColor (Color.GREEN); Gifolgazine (new int [] {0, gatewidth (),}, new int [] {0, 0 (hot) ()}, 3); }} Protected static zero initUI () {JFrame frame = new JFrame ("test"); Frame.add (new MyTriangle (200, 45), border layout. EAST); Frame.ed (new mittrigengle (85, 600), border layout. West); Frame.pack (); Frame.setVisible (true); } Public static zero main (string [] args) {SwingUtilities.invokeLater (New Runnabal) {@Override Public run zero () {initUI ();}}); }}

NB: I have to accept, the colors are more interesting: -)


No comments:

Post a Comment