JTable inside JPanel - edges hidden. - SunnyAkuma - Apr 12, 2015
I made this GUI, used a Panel that contains a Table.
Functionality is fine , but My table's sides are cut , about 5 pixels is hidden from each side of the table.
I tried to increase the size of the panel , but the table just stretches and the sides are still hidden , It's irritating cause Half scrollbar isn't visible , and of the left side the first digit of the numbers isn't visible
can someone run this programe and see what I mean
can someone provide me with a solution ?
Code import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ViewRecords extends JFrame
{
private static final long serialVersionUID = 1L;
JTable maintainanceRepariTable;
JTable breakdownRepariTable;
JPanel maintainence;
JPanel breakdown;
private JLabel maintainLabel;
private JLabel breakdownLabel;
public ViewRecords()
{
setLayout(null);
Font font1 = new Font("ARIEL BLACK", Font.PLAIN, 20);
maintainLabel = new JLabel("Maintenance Repair Records");
maintainLabel.setFont(font1);
maintainLabel.setForeground(Color.RED);
maintainLabel.setBounds(10, 10, 500, 20);
breakdownLabel = new JLabel("Breakdown Repair Records");
breakdownLabel.setFont(font1);
breakdownLabel.setForeground(Color.RED);
breakdownLabel.setBounds(10, 360, 500, 20);
String breakdownColumnNames[]={"Job Number", "Date of job", "Car Registration number","Repair Type", "Total charges"};
String maintainanceColumnNames[]={"Job Number", "Date of job", "Car Registration number","Extra Charges", "Total charges"};
Object maintainanceRecords[][]={
{"00","01","02","03","04"},
{"10","11","12","13","14"},
{"20","21","22","23","24"},
{"30","31","32","33","34"},//DUMMY TABLE VALUES
{"40","41","42","43","44"},
{"50","51","52","53","54"},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
};
Object breakdownRecords[][]={
{"00","01","02","03","04"},
{"10","11","12","13","14"},
{"20","21","22","23","24"},
{"30","31","32","33","34"},//DUMMY TABLE VALUES
{"40","41","42","43","44"},
{"50","51","52","53","54"},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
{"","","","",""},
};
maintainanceRepariTable=new JTable(maintainanceRecords,breakdownColumnNames);
maintainanceRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200));
maintainanceRepariTable.setFillsViewportHeight(true);
breakdownRepariTable=new JTable(breakdownRecords,maintainanceColumnNames);
breakdownRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200));
breakdownRepariTable.setFillsViewportHeight(true);
JButton editMaintainanceRecords = new JButton("Edit Maintenance Records");
editMaintainanceRecords.setBounds(730,60,100, 40);
editMaintainanceRecords.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
});
JButton editBreakdownRecords = new JButton("Edit Breakdown Records");
editBreakdownRecords.setBounds(730,90,100, 40);
editBreakdownRecords.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
});
JScrollPane scrollPane=new JScrollPane(maintainanceRepariTable);
JScrollPane scrollPaneBreak=new JScrollPane(breakdownRepariTable);
maintainence=new JPanel();
maintainence.setBounds(20,40,700,300);
maintainence.add(scrollPane);
maintainence.add(editMaintainanceRecords);
add(maintainence);
breakdown=new JPanel();
breakdown.setBounds(20,400,700,300);
breakdown.add(scrollPaneBreak);
breakdown.add(editBreakdownRecords);
add(breakdown);
add(maintainLabel);
add(breakdownLabel);
}
public static void main(String args[])
{
ViewRecords viewRecords=new ViewRecords();
viewRecords.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
viewRecords.setSize(750,750);
viewRecords.setVisible(true);
viewRecords.setResizable(true);
viewRecords.setTitle("Maintainance Repair Records.");
viewRecords.setLocationRelativeTo(null);
}
}
* - ☕⚛Austin⚛☕ - Apr 12, 2015
Your problem is
PHP Code
<?php maintainanceRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200)); breakdownRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200));
so try and delete those.
* - SunnyAkuma - Apr 12, 2015
(Apr 12, 2015 05:47 AM)☕⚛Austin⚛☕ Wrote: Your problem is
PHP Code
<?php maintainanceRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200)); breakdownRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200));
so try and delete those.
Can't delete those, I Need the scrollbar.
* - WildeThing - Apr 12, 2015
(Apr 12, 2015 07:23 AM)SunnyAkuma Wrote: Can't delete those, I Need the scrollbar.
You need to remove those lines. The scrollbar will show when you have enough rows - that's what they're supposed to do.
PHP Code
<?php import javax.swing.*;
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
public class ViewRecords extends JFrame { private static final long serialVersionUID = 1L; JTable maintainanceRepariTable; JTable breakdownRepariTable; JPanel maintainence; JPanel breakdown; private JLabel maintainLabel; private JLabel breakdownLabel; public ViewRecords() { setLayout(null);
Font font1 = new Font("ARIEL BLACK", Font.PLAIN, 20);
maintainLabel = new JLabel("Maintenance Repair Records"); maintainLabel.setFont(font1); maintainLabel.setForeground(Color.RED); maintainLabel.setBounds(10, 10, 500, 20);
breakdownLabel = new JLabel("Breakdown Repair Records"); breakdownLabel.setFont(font1); breakdownLabel.setForeground(Color.RED); breakdownLabel.setBounds(10, 360, 500, 20);
String breakdownColumnNames[]={"Job Number", "Date of job", "Car Registration number","Repair Type", "Total charges"}; String maintainanceColumnNames[]={"Job Number", "Date of job", "Car Registration number","Extra Charges", "Total charges"};
Object maintainanceRecords[][]={ {"00","01","02","03","04"}, {"10","11","12","13","14"}, {"20","21","22","23","24"}, {"30","31","32","33","34"},//DUMMY TABLE VALUES {"40","41","42","43","44"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"},{"50","51","52","53","54"},
{"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, }; Object breakdownRecords[][]={ {"00","01","02","03","04"}, {"10","11","12","13","14"}, {"20","21","22","23","24"}, {"30","31","32","33","34"},//DUMMY TABLE VALUES {"40","41","42","43","44"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, };
maintainanceRepariTable=new JTable(maintainanceRecords,breakdownColumnNames); // maintainanceRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200)); maintainanceRepariTable.setFillsViewportHeight(true);
breakdownRepariTable=new JTable(breakdownRecords,maintainanceColumnNames); //breakdownRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200)); breakdownRepariTable.setFillsViewportHeight(true);
JButton editMaintainanceRecords = new JButton("Edit Maintenance Records"); editMaintainanceRecords.setBounds(730,60,100, 40); editMaintainanceRecords.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } });
JButton editBreakdownRecords = new JButton("Edit Breakdown Records"); editBreakdownRecords.setBounds(730,90,100, 40); editBreakdownRecords.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } });
JScrollPane scrollPane=new JScrollPane(maintainanceRepariTable); JScrollPane scrollPaneBreak=new JScrollPane(breakdownRepariTable);
maintainence=new JPanel(); maintainence.setBounds(20,40,700,300); maintainence.add(scrollPane); maintainence.add(editMaintainanceRecords); add(maintainence);
breakdown=new JPanel(); breakdown.setBounds(20,400,700,300); breakdown.add(scrollPaneBreak); breakdown.add(editBreakdownRecords); add(breakdown);
add(maintainLabel); add(breakdownLabel); }
public static void main(String args[]) {
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) {
}
ViewRecords viewRecords=new ViewRecords(); viewRecords.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); viewRecords.setSize(750,750); viewRecords.setVisible(true); viewRecords.setResizable(true); viewRecords.setTitle("Maintainance Repair Records."); viewRecords.setLocationRelativeTo(null); } }
There you go.
htt p://i .imgur.com/xYLQCms.png
* - SunnyAkuma - Apr 12, 2015
(Apr 12, 2015 07:57 AM)WildeThing Wrote: You need to remove those lines. The scrollbar will show when you have enough rows - that's what they're supposed to do.
PHP Code
<?php import javax.swing.*;
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
public class ViewRecords extends JFrame { private static final long serialVersionUID = 1L; JTable maintainanceRepariTable; JTable breakdownRepariTable; JPanel maintainence; JPanel breakdown; private JLabel maintainLabel; private JLabel breakdownLabel; public ViewRecords() { setLayout(null);
Font font1 = new Font("ARIEL BLACK", Font.PLAIN, 20);
maintainLabel = new JLabel("Maintenance Repair Records"); maintainLabel.setFont(font1); maintainLabel.setForeground(Color.RED); maintainLabel.setBounds(10, 10, 500, 20);
breakdownLabel = new JLabel("Breakdown Repair Records"); breakdownLabel.setFont(font1); breakdownLabel.setForeground(Color.RED); breakdownLabel.setBounds(10, 360, 500, 20);
String breakdownColumnNames[]={"Job Number", "Date of job", "Car Registration number","Repair Type", "Total charges"}; String maintainanceColumnNames[]={"Job Number", "Date of job", "Car Registration number","Extra Charges", "Total charges"};
Object maintainanceRecords[][]={ {"00","01","02","03","04"}, {"10","11","12","13","14"}, {"20","21","22","23","24"}, {"30","31","32","33","34"},//DUMMY TABLE VALUES {"40","41","42","43","44"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"},{"50","51","52","53","54"},
{"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, }; Object breakdownRecords[][]={ {"00","01","02","03","04"}, {"10","11","12","13","14"}, {"20","21","22","23","24"}, {"30","31","32","33","34"},//DUMMY TABLE VALUES {"40","41","42","43","44"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"50","51","52","53","54"}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}, };
maintainanceRepariTable=new JTable(maintainanceRecords,breakdownColumnNames); // maintainanceRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200)); maintainanceRepariTable.setFillsViewportHeight(true);
breakdownRepariTable=new JTable(breakdownRecords,maintainanceColumnNames); //breakdownRepariTable.setPreferredScrollableViewportSize(new Dimension(700,200)); breakdownRepariTable.setFillsViewportHeight(true);
JButton editMaintainanceRecords = new JButton("Edit Maintenance Records"); editMaintainanceRecords.setBounds(730,60,100, 40); editMaintainanceRecords.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } });
JButton editBreakdownRecords = new JButton("Edit Breakdown Records"); editBreakdownRecords.setBounds(730,90,100, 40); editBreakdownRecords.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } });
JScrollPane scrollPane=new JScrollPane(maintainanceRepariTable); JScrollPane scrollPaneBreak=new JScrollPane(breakdownRepariTable);
maintainence=new JPanel(); maintainence.setBounds(20,40,700,300); maintainence.add(scrollPane); maintainence.add(editMaintainanceRecords); add(maintainence);
breakdown=new JPanel(); breakdown.setBounds(20,400,700,300); breakdown.add(scrollPaneBreak); breakdown.add(editBreakdownRecords); add(breakdown);
add(maintainLabel); add(breakdownLabel); }
public static void main(String args[]) {
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) {
}
ViewRecords viewRecords=new ViewRecords(); viewRecords.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); viewRecords.setSize(750,750); viewRecords.setVisible(true); viewRecords.setResizable(true); viewRecords.setTitle("Maintainance Repair Records."); viewRecords.setLocationRelativeTo(null); } }
There you go.
htt p://i .imgur.com/xYLQCms.png
Thanks that worked.
Can you tell me how to add a Horizontal Scroll bar too?
I don't need it here , but just for the sake of knowing.
* - WildeThing - Apr 12, 2015
(Apr 12, 2015 08:48 AM)SunnyAkuma Wrote: Thanks that worked.
Can you tell me how to add a Horizontal Scroll bar too?
I don't need it here , but just for the sake of knowing.
Hmm, I dunno. I think you'd have to define the sizes of each columns. Like, if you set them all at fixed widths that altogether add up to a total width greater than the scroll pane, then it will add a horizontal scroll bar by itself.
|