• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

About size of content pane within the scroll pane

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The scroll bar that i am generating is very small and it has contentpane comonent in it i want the content pane component size to increase and i want to specify it according to my requirements .

package com.brainmentors.testengine.user.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;

import com.brainmentors.testengine.util.constants.CommonDao;
import com.brainmentors.testengine.util.constants.QueryConstants;

import javax.swing.JScrollPane;
import javax.swing.JButton;
import java.awt.FlowLayout;

public class SelectTestView extends JFrame {

private JPanel contentPane;
private JPanel contentPane1;
   private JRadioButton Button ;
   private String TestName;
    private ButtonGroup bg =new ButtonGroup();
    JScrollPane scrollPane ;
    ArrayList<JRadioButton> button;
    static SelectTestView frame;
    private JButton button_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame= new SelectTestView();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void selectTest() {
ArrayList<String> TestList =new ArrayList<>();

Connection connection =null;
PreparedStatement pstmt =null;
ResultSet rs=null;
try {
connection=CommonDao.getConnection();
pstmt=connection.prepareStatement(QueryConstants.fetchTest);
rs=pstmt.executeQuery();
while(rs.next()) {
TestList.add(rs.getString("testname"));
}
if(TestList.size()>0) {
connection.commit();
}else{
connection.close();
}

} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
try {
connection.rollback();
}catch(SQLException e) {
e.printStackTrace();
}
}catch( SQLException e1) {
e1.printStackTrace();
}

int x=40;
System.out.println("The size of the test list "  + TestList.size());
   button=new ArrayList<>();
for(int i=0;i<TestList.size();i++) {
Button= new JRadioButton(TestList.get(i));
System.out.println(TestList.get(i));

   button.add(Button);
Button.setFont(new Font("Times New Roman", Font.BOLD, 15));
System.out.println("button loop");
Button.setBounds(40,x,100, 87);
bg.add(Button);
contentPane1.add(Button);
x+=i*1000;
}
       
for( int i=0;i<button.size();i++) {
System.out.println("The test buttons " +button.get(i).getText());
}
}
public boolean  fetchTest() {

for(int i=0;i<button.size();i++) {

if(button.get(i).isSelected()) {

String testName=button.get(i).getText().trim();
System.out.println("The test name selected is " + testName);
TakeTestView frame1= new TakeTestView(testName);
frame1.setVisible(true);

frame.dispose();
return true;
}



}

return false;


}
/**
* Create the frame.
*/
public SelectTestView() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1000, 600);
contentPane = new JPanel();
contentPane1 = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

scrollPane= new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
contentPane.add(scrollPane);
contentPane1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
contentPane1.setBounds(100,100, 900, 600);
scrollPane.setViewportView(contentPane1);

button_1 = new JButton("Submit ");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(fetchTest()) {

}else {
JOptionPane.showMessageDialog(null, "Select atleast one button ");
}
}
});
button_1.setFont(new Font("Times New Roman", Font.BOLD, 15));
contentPane.add(button_1);
selectTest();
bg.clearSelection();
}
}
 
Rancher
Posts: 3063
23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question is about a scrollbar.

So post an SSCCE demonstrating the problem.

We don't have access to your databse to demonstrate the problem with hard coded data so we can compile and test the code to see what is happening.

When you post the code make sure you use the code formatting tags so the code is formatted and we can read it easier.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!