The Artima Developer Community
Sponsored Link

Java Answers Forum
JComponent Related-Questions

1 reply on 1 page. Most recent reply: May 18, 2004 3:26 PM by Daniel Ray

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Que Trac

Posts: 1
Nickname: icedrake
Registered: May, 2004

JComponent Related-Questions Posted: May 16, 2004 1:35 AM
Reply to this message Reply
Advertisement
I have several questions. The first question is about the
JTable. How should I modify my code to in order to set the
table to be uneditable?

<java>
String[] columnNames = {"Item", "Price"};
Object[][] data = {{"Item 1", "Price 1"}, {"Item 2", "Price 2"}};
JTable table = new JTable(data, columnNames);
</java>

The second question is about the JTextField. I set the
textfield to a certain size, but I can input more than that
fixed size. How should I modify my code to in order to set
that the input is not more than the fix size?

<java>
JLabel username = new JLabel("User Name");
final JTextField usernameField = new JTextField(12);
</java>

The third question is about JSplitPane. I want to split my
panel into two parts, so I use a JSplitPane. The problem
with it is that the user resizes the divider. Is there a way
to prevent the divider from begin moved?


The last question is about file I/O. I have a file that I
will use to read and write data to it. Is there a class or
an easy way I can use to implement writing process? Because
when you write, delete, or change something in the middle of
the file, it will affect the data below.


Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: JComponent Related-Questions Posted: May 18, 2004 3:26 PM
Reply to this message Reply
For your JTable you can subclass DefaultTableModel and override the isCellEditable(int row, int column) method to return false. Be sure to use setModel(your_table_model) on your JTable.

Here are two links for your JTextfield question. The JTextField(12) means that you are showing 12 characters. It does not limit it to 12 characters.
http://www.javaworld.com/javaworld/javaqa/2000-05/02-qa-0512-textbox.html or http://www.javaalmanac.com/egs/javax.swing.text/LimitText.html

Use a different component .. like two JPanels or two JTextAreas instead of a JSplitPane. I can't think of why you would use a JSplitPane if you didn't want to 'split'.

Your IO question is unclear. Do you mean to update the ui as the file is modified? Maybe you could explain the need to do this. Reading and writing to/from a file is simple enough as is notifying your component models of data changes.

I hope this helps and I don't mind helping you solve the last two issues. Just give me some more detail to work with.

Flat View: This topic has 1 reply on 1 page
Topic: Thank You To Java Answers Forum Previous Topic   Next Topic Topic: Newbie code Please help if u can .

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use