The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

why the scollbar had no effect?

Posted by hindsight on February 06, 2002 at 2:33 AM

HERE IS PART OF THE CODE,
THE TABLE OWNED MANY COLUMNS AND I WANT TO SHOW EVERY COLUMN IN ITS FITTEST SIZE AND PULL SCROLLBAR TO SHOW THOSE CAN'T BE SHOWN.
IF I USE A METHOD TO SHOW THE FIT SIZE,THE HORIZON SCROLLBAR NEVER APPEAR AND ONLY SHOW PART OF THE COLUMS.IF I DIDN'T USE THE
METHOD,IT SHOW ALL WITHOUR SCROLLBAR BUT WITHOUT WHOLE NAME OF THE COLUMN.HOW COULD I DO IT OR WHERE IS WRONG IN THE CODE?
THANX IN ADVANCE.


import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.*;
import java.util.*;
import org.w3c.dom.*;
import java.io.File;
import java.text.*;

public class MainQueryTask extends JPanel {
ResourceBundle myRB = null;
Iterator iter = null;
private DefaultTableModel model;
ListSelectionModel midSelections;
JPanel mainPanel = new JPanel();
JScrollPane headPane;
Object[][] dataValue = new Object[10][18];
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTable headTable = new JTable();
JTable dtlTable = new JTable();
JButton jButton1 = new JButton();
JPanel resultPane = new JPanel();
JPanel resdtlPane = new JPanel();
public MainQueryTask() {
try {
myRB = Toolkit.getResource();
jbInit();
} catch(Exception e) {
String message = e.getMessage();
JOptionPane.showMessageDialog(null, message, "Add Task",
JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}

private void jbInit() throws Exception {
TaskManager taskManager = new TaskManager();
HashMap map = taskManager.getTaskList();
model = new DefaultTableModel();
Set key = map.keySet();
Iterator tasklist = key.iterator();
while(tasklist.hasNext()){
selectTable.addItem((String)tasklist.next());
}
jButton1.addActionListener( new ActionListener() {
public void actionPerformed (ActionEvent e) {
queryCommit();
}
});

model.addColumn(myRB.getString("HandExcuteTask_Sequence"));
model.addColumn(myRB.getString("ViewLogMsg__UpdateTime"));
model.addColumn(myRB.getString("MainCustomTask_TaskName"));
model.addColumn(myRB.getString("ViewLogMsg__BookTime"));
model.addColumn(myRB.getString("MainCustomTask_TaskType"));
model.addColumn(myRB.getString("ViewLogMsg_StoreID"));
model.addColumn(myRB.getString("ViewLogMsg_TransferDirection"));
model.addColumn(myRB.getString("ViewLogMsg__ExecuteMethod"));
model.addColumn(myRB.getString("ViewLogMsg__FailureTimes"));
model.addColumn(myRB.getString("ViewLogMsg_XmlCount"));
model.addColumn(myRB.getString("ViewLogMsg__RecordsCount"));
model.addColumn(myRB.getString("ViewLogMsg__ExcuteResult"));
model.addColumn(myRB.getString("ViewLogMsg_BeginDate"));
model.addColumn(myRB.getString("ViewLogMsg__EndDate"));
model.addColumn(myRB.getString("ViewLogMsg__RetryTimes"));
model.addColumn(myRB.getString("ViewLogMsg_MaxRetryTimes"));
model.addColumn(myRB.getString("ViewLogMsg__MakeUserId"));
model.addColumn(myRB.getString("ViewLogMsg_MakeDate"));

headTable = new JTable(model);
headTable.setFont(EcommToolkit.getFont());
headTable.setForeground(Color.black);
headTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
headPane = new JScrollPane(headTable);
headPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
headPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
}
}
});
mainPanel.setLayout(null);
this.setLayout(new BorderLayout());
resultPane.setLayout(new BorderLayout());
jLabel1.setText(myRB.getString("ViewLogMsg_Title"));
jLabel2.setText("");
jLabel3.setText(myRB.getString("ViewLogMsg__StartTime"));
jLabel5.setText(myRB.getString("ViewLogMsg_Store_TableName"));
jLabel6.setText(myRB.getString("ViewLogMsg__BookTime"));
jLabel4.setText(myRB.getString("ViewLogMsg__EndTime"));
jLabel1.setBounds(new Rectangle(31, 31, 100, 22));
jLabel2.setBounds(new Rectangle(140, 31, 60, 22));
jLabel3.setBounds(new Rectangle(30, 109, 100, 21));
jLabel4.setBounds(new Rectangle(30, 143, 100, 21));
jLabel5.setBounds(new Rectangle(30, 178, 100, 21));
jLabel6.setBounds(new Rectangle(30, 74, 100, 21));
resultPane.setBounds(new Rectangle(26, 215, 600, 100));
jButton1.setText(myRB.getString("ViewLogMsg_Query"));
jButton1.setBounds(new Rectangle(465, 185, 62, 20));
mainPanel.add(jLabel1, null);
mainPanel.add(jLabel2, null);
mainPanel.add(jLabel3, null);
mainPanel.add(jLabel5, null);
mainPanel.add(jLabel6, null);
mainPanel.add(jLabel4, null);
resultPane.add(headPane);
mainPanel.add(resultPane, null);
mainPanel.add(jButton1, null);
this.add(mainPanel);
}


public static void main(String[] args) {
JFrame frame = new JFrame();
MainQueryTask mainQueryTask = new MainQueryTask();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
Dimension dm = Toolkit.getDefaultToolkit().getScreenSize();
int x1 = (int) (dm.getWidth() / 12);
int y1 = (int) (dm.getHeight() / 12);
int x2 = (int) (5 * dm.getWidth() / 6);
int y2 = (int) (5 * dm.getHeight() / 6);
System.out.println("x1 =" + x1);
System.out.println("x2 =" + x2);
System.out.println("y1 =" + y1);
System.out.println("y2 =" + y2);
frame.setBounds(x1,y1, x2, y2);
frame.setContentPane(mainQueryTask);
frame.setVisible(true);
}
//SET THE FITTEST SIZE OF EVERY COLUMN
private void setTableColumnSize() {
TableColumnModel tableColumnModel = headTable.getColumnModel();
TableColumn idColumn = tableColumnModel.getColumn(0);
int descWidth = EcommToolkit.getColumnFitWidth(headTable, 0);
idColumn.setMinWidth(descWidth);
idColumn.setMaxWidth(descWidth);
idColumn.setPreferredWidth(descWidth);
}
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us