logo
down
shadow

Why JPanel doesn't have all the lines in my app?


Why JPanel doesn't have all the lines in my app?

By : thien
Date : November 22 2020, 10:48 AM
hop of those help? My JPanel is supposed to contain 300 lines of text, but no matter what I do to enlarge it's size, it won't contain all 300 line of text, why and how to fix ? Here is my code : , I figured it out, here is the answer :
code :
class A_Chart_Panel extends JPanel
{
  Vector<String> String_Vector;
  final int PAD=2;

  A_Chart_Panel(Vector<String> String_Vector)
  {
    this.String_Vector=String_Vector;
    setPreferredSize(new Dimension(530,String_Vector.size()*12));
    Draw_Chart();
  }

  void Draw_Chart()
  {
    Out("String_Vector.size() = "+String_Vector.size());
  }

  protected void paintComponent(Graphics g)
  {
    super.paintComponent(g);
    Graphics2D g2=(Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    int w=getWidth();
    int h=getHeight();
    g2.drawLine(PAD+w*9/15,PAD,PAD+w*9/15,h-PAD);
    g2.drawLine(PAD+w*9/15,PAD,PAD+w*9/15-5,PAD+26);
    g2.drawLine(PAD+w*9/15,PAD,PAD+w*9/15+5,PAD+26);   

    double xScale=(w-2*PAD)/(20);
    double maxValue=String_Vector.size();
    double yScale =(h-2*PAD)/maxValue;
    // The origin location.  
    int x0=PAD;
    int y0=h-PAD;
    g2.setPaint(Color.BLUE);
    for (int j=0;j<String_Vector.size();j++)
    {
      int x=x0+(int)(xScale*(j+1));
      int y=10+(int)(yScale*j);
      g2.drawString(String_Vector.elementAt(j),5,y);
    }
  }


Share : facebook icon twitter icon
JPanel doesnt allow positioning component

JPanel doesnt allow positioning component


By : Paul Allen
Date : March 29 2020, 07:55 AM
To fix the issue you can do Without a working example, it appears you've left the default layout for the JPanel (which is a FlowLayout).
Start by creating a custom panel for each of your views, it will make it easier to manage and the apply them to the JTabbedPane.
code :
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Test {

    public static void main(String[] args) {
        new Test();
    }

    public Test() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                JFrame frame = new JFrame("Testing");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                JTabbedPane tp = new JTabbedPane();
                tp.add("Person", new JPanel());
                tp.add("Work Detail", new TestPane());

                frame.add(tp);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }

    public class TestPane extends JPanel {

        private JTextField name;
        private JTextField serial;
        private JTextField id;
        private JTextField email;

        private JComboBox level;

        public TestPane() {
            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.anchor = GridBagConstraints.EAST;
            gbc.insets = new Insets(2, 2, 2, 2);

            add(new JLabel("Name"), gbc);
            gbc.gridx += 2;
            add(new JLabel("Sr No"), gbc);
            gbc.gridx = 0;
            gbc.gridy++;
            add(new JLabel("ID"), gbc);
            gbc.gridx += 2;
            add(new JLabel("Email ID"), gbc);

            name = new JTextField(10);
            serial = new JTextField(10);
            id = new JTextField(10);
            email = new JTextField(10);

            level = new JComboBox(new String[]{"Manager", "Eng Lead", "Eng Designer", "Jr Designer"});

            gbc.anchor = GridBagConstraints.WEST;
            gbc.gridx = 1;
            gbc.gridy = 0;
            add(name, gbc);
            gbc.gridx += 2;
            add(serial, gbc);
            gbc.gridx = 1;
            gbc.gridy++;
            add(id, gbc);
            gbc.gridx += 2;
            add(email, gbc);

            gbc.gridx = 0;
            gbc.gridy++;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            add(level, gbc);

            gbc.gridy++;
            gbc.anchor = GridBagConstraints.CENTER;
            add(new JButton("Save"), gbc);
        }

    }

}
JPanel paintComponent(...) doesnt work

JPanel paintComponent(...) doesnt work


By : Eartha
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further My first guess is that you're passing the wrong x and y.The x and y in g.drawImage are the coordinates of the top left corner, not the size of the image, so usually they are set directly at 0 (that means, g.draWimage(imga, x, y, this).
Java JPanel doesnt get painted

Java JPanel doesnt get painted


By : Tilo von Brandis
Date : March 29 2020, 07:55 AM
will help you Your render method on the JPanel should only update state, and call for a repaint. The painting will be done in paintComponent as a result of the call to repaint.
Java - Why doesnt the size of jpanel work

Java - Why doesnt the size of jpanel work


By : user2558103
Date : March 29 2020, 07:55 AM
it fixes the issue Just add your Exercise1 JPanel to the JFrame's content pane instead.
Also, don't forget to ensure that any code that touches your UI is done from the event dispatch thread.
code :
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import java.awt.Dimension;
import java.net.InetAddress;

public class Exercise1 extends JPanel {
    private JLabel jlblIP = new JLabel("IP= 221.1231.231");
    private JLabel jlblName = new JLabel("Namn = DAMSKDLASM");
    private JLabel jlblHostIP = new JLabel("Host ip --------");
    private JLabel jlblHostName = new JLabel("Host name:");
    private JTextField jtxtfield = new JTextField("");
    private InetAddress ipaddress;

    public Exercise1(){
        setPreferredSize(new Dimension(200,200));
        add(jlblIP);

    }

    public static void main(String[] args) {
        Exercise1 mainjpn = new Exercise1();
        Runnable r = new Runnable() {
            public void run() {
                JFrame jframe = new JFrame();
                jframe.getContentPane().add(mainjpn);
                jframe.pack();
                jframe.setDefaultCloseOperation(jframe.EXIT_ON_CLOSE);
                jframe.setVisible(true);
            }
        };
        SwingUtilities.invokeLater(r);
    }
}
JPanel doesnt display the drawing

JPanel doesnt display the drawing


By : Ataro
Date : March 29 2020, 07:55 AM
To fix this issue Here is the answer, I forgot to set the size of the drawingBoard JPanel :-)
Related Posts Related Posts :
  • How to show downshift + popper on top of material-ui dialog?
  • jQuery file upload and RequireJS configuration
  • How to send the result of a select query to a message body of a mail in oracle 10G
  • Worklight common build failing with "Failed to update main HTML file"
  • pg_listening_channels() is not returning the channels name
  • Asset management in ZF2
  • Does the Firefox add-on sdk allow direct modification of the http response byte stream?
  • How to remove menu hardware key from your android app
  • Identifying programming language
  • Use shell commands to find Makefile.am in configure.ac
  • Mono Compiler as Service or Microsoft Roselyn for a vb parser
  • How to add extra root nodes for not well formed XML structure?
  • which Uncrustify setting replaces blank lines with indenting spaces?
  • mac OSX Lion Homebrew install curl (77)
  • In Project Euler 47, why is 2^2 considered a prime number distinct from 2?
  • browserstack requesting localhost:45691
  • What was the real reason why Google is chosing RenderScript instead of OpenCL?
  • Mandrill Inbound Email routing
  • Prevent checkElementIndex() Guava function from concatenating additional response to existing error message
  • Arduino and Raspberry Pi Serial communication + multiple variables
  • convert a 960 grid based site to responsive
  • Should it be possible to have more than one DocuSign account (DEMO) with the same email address?
  • Is it possible to limit ammount of concurrent builds in Travis-CI
  • Selecting languages with specific ISO code
  • Deprecated vs Unsupported SDK
  • Verifying ClearCase files have been labeled properly
  • What's the difference between "Bag of Words" and "Bag of features" in computer vision?
  • Is there a way to tell Serde to use a struct field as a map's key?
  • ld:framework not found sfml
  • nice, go-idiomatic way of using a shared map
  • IzPack ChmodInstallerListener.jar
  • Breaking down tasks of user stories between developer and QA
  • Dropwizard service not starting properly
  • How to override devise invitable actions
  • Coded UI. How can I change TimeOut in Find() method
  • Why when I click on the update button error TypeError: r is undefined happen?
  • Visio Component Diagram - Required Interface
  • Lucene: fast(er) to get docs in bulk?
  • can I use windows 8 font (Segoe UI)for my web app?
  • Using Flask Session in Gevent Socket-IO
  • Difference between recommended and suggested cookbooks
  • Dynamic Forms (Formsets) in Flask / WTForms?
  • Image Servlet doesn't want to show image in browser (FireFox, IE..) but in Eclipse browser works?
  • Logback - how to get each logger logging to a separate log file?
  • In Crystal Reports, how do I keep a row from printing if the value is null?
  • iOS 6 Audio multi-route - use external microphone AND internal speaker simultaneously
  • Adding Comments in JasperReports template (jrxml)
  • Servicestack mini profiler
  • Logging with Castle Windsor, the Logging Facility and log4net
  • Subscribe for instances list update in GCE autoscaled group
  • Generating a unique QR code for each Order in Woocommerce
  • libvirtError: internal error Cannot find suitable CPU model for given data
  • CKEditor changing content automatically
  • Pass double pointer in a struct to CUDA
  • Apache Camel for TCP based streamer
  • How to convert old CDC mainframe PRUs to bytes?
  • compilation on Blue Gene Q - ELF header
  • Set border of a jasper subreport having a title and a detail band
  • How to highlight tpl file?
  • cygwin: Starting cron as a service (access denied)
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org