Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: code with problem in layout and scrolling

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question code with problem in layout and scrolling

    I have written a code, and some extracted from netbeans for fixing a textfied and buttons for java swing program...
    But the textfield is appearing .. but buttons appear after i hover with mouse.
    and the same time it is not scrolling also...when i included Jscrollbar...
    Important thing below the buttons i have some paint functions to performs... my window will come around 1300 * 900
    or more than that...
    For that i need to scroll the window.. but i am not able to ...
    i am pasting the code can anyone solve the code for me...

    PS... some of the variable which weren't used in the piece of code were used in the later half of the code...
    Please do reply asap

    import java.io.*;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Line2D;
    import java.awt.geom.Rectangle2D;
    import javax.swing.JPanel;
    import java.util.List;
    import java.lang.*;
    import java.awt.event.*;
    import javax.swing.JFrame;
    import java.awt.Color;
    import java.applet.*;
    import javax.swing.*;
    import javax.swing.JTextField;
    import java.applet.Applet;
    import java.awt.*;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    import javax.swing.undo.*;
    import javax.swing.JDialog;
    import javax.swing.JScrollPane;
    import javax.swing.JFrame;
    import java.awt.image.BufferedImage;
    import javax.imageio.*;
    import java.awt.FlowLayout;
    //import java.awt.GroupLayout;
    import java.awt.Color;
    import java.awt.MouseInfo;
    import java.awt.Point;
    import java.awt.PointerInfo;
    import java.awt.Robot;
    import java.util.Arrays;
    import java.awt.event.AdjustmentEvent;
    import java.awt.event.AdjustmentListener;
    public class secondapp extends Firstapplet12 implements MouseListener {
    static JFrame frame;
    TextField text1;
    Button but1,but2;String kt;
    String sss1,sss2,sss3,sss4,sss5,sss6;
    String t1,t3,t5;
    String[] t2 = new String[8];
    String[] t4;
    String w1,w3;
    String[] w2 = new String[8];
    String[] w4;
    String[] w5;
    String[] p1 = new String[50];
    String[] w6= new String[50];
    String p2,p3,p4,p5;
    int xpos,ypos,j1,h=5,tj,pj;
    double xx1=200,xx2=200,yy1=150.0,yy2=150.0,at,as,at1,at2, w;
    double xt4=0.0,yt4=0.0,xt5=0.0,yt5=0.0,xt6=0.0,yt6=0.0;
    String userHomePath = System.getProperty("user.home");File userHome = new File(userHomePath);
    String[] sLine = new String[8];
    String strg;int kte=0;int ab=0;
    int jt =0;
    PointerInfo pointer;
    Color color;
    File fz; int fi =0;
    File fn;File[] listfn;
    String uni1,dispn1,core1;int ut=0;
    String[] uni2 = new String[50];

    public javax.swing.JButton jButton1;
    public javax.swing.JButton jButton2;
    public javax.swing.JButton jButton3;
    public javax.swing.JButton jButton4;
    public javax.swing.JScrollBar b1;
    public TextField jTextField1;
    BufferedImage bufferedImage;
    String funk;

    Font fon1,fon2,fon3;
    int tk;
    public String ss1,ss2,st1,st2,sg1,sg2;
    String rst;
    final String gst;
    UndoManager manager = new UndoManager();
    final JPanel tp = new JPanel();//JPanel cards;
    Graphics g;
    public secondapp(String tt)
    { this.gst = tt;
    Graphics g;
    initComponents();
    repaint();

    }

    public void initComponents()
    {

    JFrame frame = new JFrame("secondapp");
    // for showing scroll bar in frame ---> JScrollBar scrollBar=new JScrollBar();
    //tp,J.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZON TAL_SCROLLBAR_ALWAYS);

    jTextField1 = new TextField();
    tp.add(jTextField1);

    JButton jButton3 = new JButton();jButton3.setText("Export");tp.add(jButto n3);jButton3.setVisible(true);//jButton3.setBounds(8,82, 5, 180);
    JButton jButton1 = new JButton();tp.add(jButton1);jButton1.setText("Gene in Query Genome");tp.add(jButton1);jButton1.setVisible(true );//jButton1.setPreferredSize(new Dimension(10, 10));
    JButton jButton2 = new JButton();tp.add(jButton2);jButton2.setText("Gene in Reference Genome");tp.add(jButton2);jButton2.setVisible(true );

    //tp.add(jButton1, BorderLayout.NORTH);
    fon1=new Font("Sanserif",Font.BOLD,12);
    fon2=new Font("Sanserif",Font.BOLD,11);
    fon3=new Font("TimesRoman",Font.PLAIN,12);//TimesRoman Courier JScrollBar jsb1 = new javax.swing.JScrollBar(JScrollBar.VERTICAL);tp.add (jsb1);

    JScrollPane jp = new JScrollPane(tp);
    JEditorPane ep = new JEditorPane();
    jp.setViewportView(ep);

    frame.getContentPane().add(jp);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(1400,1000);

    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    }
    });

    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton2ActionPerformed(evt);
    }
    });
    jButton3.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton3ActionPerformed(evt);
    }
    });



    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

    this.setLayout(layout);
    frame.pack();

    layout.setHorizontalGroup(

    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()

    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
    .addComponent(jButton2))
    //.addComponent(scrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    //.addComponent(scrollBar))
    .addGroup(layout.createSequentialGroup()
    .addGap(118, 118, 118)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addContainerGap(75, Short.MAX_VALUE))
    );

    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(17, 17, 17)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))

    )
    );


    /* layout.setHorizontalGroup(layout
    .createSequentialGroup()
    .addGroup(
    layout.createParallelGroup(GroupLayout.Alignment.L EADING).addComponent(jButton1)
    .addComponent(jButton2).addComponent(jButton3)));

    // Vertical arrangement
    layout.setVerticalGroup(layout
    .createSequentialGroup()
    .addGroup(
    layout.createParallelGroup(GroupLayout.Alignment.B ASELINE).addComponent(jButton1))

    .addGroup(
    layout.createParallelGroup(GroupLayout.Alignment.B ASELINE).addComponent(jButton2))
    .addGroup(
    layout.createParallelGroup(GroupLayout.Alignment.L EADING)
    .addComponent(jButton3)));

    */


    addMouseListener(this);


    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: code with problem in layout and scrolling

    Make sure things are in the correct order. Have you added all the components to panels and all the panels to the frame before you pack and setVisible the frame?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: code with problem in layout and scrolling

    it is in correct order ... i have added all the componenets to panel

Similar Threads

  1. Drag and drop scrolling problem
    By Jack_Maloney in forum AWT / Java Swing
    Replies: 1
    Last Post: January 18th, 2012, 08:23 PM
  2. Layout related problem
    By Gaurav18 in forum Member Introductions
    Replies: 3
    Last Post: September 14th, 2011, 05:12 AM
  3. Problem with layout manager
    By mDennis10 in forum AWT / Java Swing
    Replies: 1
    Last Post: September 4th, 2011, 07:47 PM
  4. Calculator layout problem
    By Choiseymitsu in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 28th, 2011, 08:04 AM
  5. problem in managing layout
    By namreen in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 26th, 2010, 12:52 AM