Make a (get) component without pack()
HelloI'm trying to implement for a covering table header. In this example, scrollPane header is defined AFTER the framework was achieved with pack().
In my application, however, I have several different tables that I showed a common dialog, which I pass the corresponding array containing only scrollPane. Is there a way to get the scrollPane realized before be displayed? Currently, I met a NullPointerException (to the arrow "->"). I tried doLayout() and validate() nothing helps.
import java.awt.*;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
import javax.swing.table.*;
public class MultiSpanHeader1 {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new MultiSpanHeader1().makeUI();
}
});
}
public void makeUI() {
final JFrame frame = new JFrame("MultiSpanHeader test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
MyTable myTable= new MyTable();
JScrollPane scroll= new JScrollPane(myTable);
JPanel panel = new JPanel(new GridLayout(2, 1));
panel.add(myTable.dummyHeader);
panel.add(myTable.getTableHeader());
// -->
System.out.println(scroll.getColumnHeader()); // null
scroll.getColumnHeader().setView(panel); // NPE
new TableDialog(frame, scroll);
}
class TableDialog extends JDialog {
public TableDialog(Frame parent, JScrollPane scroll) {
super(parent, true);
setLocationRelativeTo(parent);
add(scroll);
setVisible(true);
}
}
class MyTable extends JTable {
final JTableHeader dummyHeader;
public MyTable() {
super(5, 6);
getTableHeader().setReorderingAllowed(false);
final TableColumnModel model = getColumnModel();
Enumeration<TableColumn> enumColumns = model.getColumns();
final List<TableColumn> columns = Collections.list(enumColumns);
final JTable dummy = new JTable(0, 3);
dummyHeader= dummy.getTableHeader();
dummyHeader.setReorderingAllowed(false);
dummyHeader.setResizingAllowed(false);
final TableColumnModel dummyModel = dummy.getColumnModel();
Enumeration<TableColumn> enumDummyColumns = dummyModel.getColumns();
final List<TableColumn> dummyColumns = Collections.list(enumDummyColumns);
model.addColumnModelListener(new TableColumnModelListener() {
@Override
public void columnAdded(TableColumnModelEvent e) {
}
@Override
public void columnRemoved(TableColumnModelEvent e) {
}
@Override
public void columnMoved(TableColumnModelEvent e) {
}
@Override
public void columnMarginChanged(ChangeEvent e) {
dummyColumns.get(0).setWidth(columns.get(0).getWidth());
dummyColumns.get(1).setWidth(columns.get(1).getWidth() +
columns.get(2).getWidth());
dummyColumns.get(2).setWidth(columns.get(3).getWidth() +
columns.get(4).getWidth() + columns.get(5).getWidth());
}
@Override
public void columnSelectionChanged(ListSelectionEvent e) {
}
});
}
}
}
You will need to substitute JTable #configureEnclosingScrollPane () to do nothing and use get #setColumnHeaderView what auto creates the window:
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class TestTable5 {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JTable table = new JTable(5, 5) {
@Override
protected void configureEnclosingScrollPane() {
// do nothing, custom table header
}
};
JScrollPane pane = new JScrollPane(table);
pane.setColumnHeaderView(new JLabel("Hi!"));
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(pane);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
Tags: Java
Similar Questions
-
How to use the declarative component without deployed as JAR
Hi all
I want to create a reusable component (declarative component) for PanelHeader with default features packed in I want to use in my application. Because this component will be used only in my project, I don't see a use to go through the process of creating a jar and deploying it before using it. Is it possible to use this component without creating a JAR.
Thank you
-Srini.User 895137,
your welcome to ignore the best practices in the development of the ADF. The declarative elements are deployed in the libraries of the ADF. If you keep the declarative component in the application then project you will have a chance to deploy independent of the application (which means that your ADF library contain more than just the source of the component (which is where your nightmare begins)). Therefore, best practices
1. create the declarative component in a new project in JDeveloper. Follow
http://download.Oracle.com/docs/CD/E21764_01/Web.1111/b31973/af_reuse.htm#BABJBFDD
2. If you don't ant to deploy components in a tag library, use declarative dynamic components (will not deploy-able in many applications, as you mentioned your future plan is), as shown here
http://download.Oracle.com/docs/CD/E21764_01/apirefs.1111/e12419/tagdoc/af_declarativeComponent.html
http://download.Oracle.com/docs/CD/E21764_01/apirefs.1111/e12419/tagdoc/af_componentDef.html
http://download.Oracle.com/docs/CD/E21764_01/apirefs.1111/e12419/tagdoc/af_xmlContent.htmlFrank
-
Yahoo password email changed computer but the iPhone and iPad can always GET mails without updating the password...
Normally, it should show as 'could not load the mail' or 'impossible to download the mail' or 'Please verify your password... "
It's really wired.You are probably using IMAP
Update contained in one place - it synchronizes across devices - all as is your email
With POP accounts, you'd see what shows your question
-
How can I get deleted without backup notes?
I had a ton of notes recorded on my phone and everything trying to change my email preferences, I deleted one of the accounts out of my phone, but he took all the notes of this account with it! I tried to back up my phone but it says I don't have enough space on the left, and also itunes automatically backed it up to my computer for me as soon as I plugged in my phone... How do I get it without having to use the backup!
Thank you very much...
You can not recover the notes now unless they are in an old backup in iTunes.
-
How to get XP service pack 3 whan it is no longer available for download?
How to get XP service pack 3 whan it is no longer available for download?
Clark
It is here http://www.microsoft.com/en-gb/download/details.aspx?id=24
-
need to get the Service Pack 2 and 3 for XP home
Recently installed new h-drive. Re-installed XP Home with services Pack 1 a. I need to get the Service Pack 2 and 3, but none of Microsoft download sites will work for me. What should I do to fix this?
You don't need sp2 (which is a chance, l because the sp2 link no longer works).
Download sp 3 here: http://www.microsoft.com/en-us/download/details-b.aspx?id=24
First read this: HOW TO get WinXP SP1 or SP2 fully patched after a 'clean install': http://groups.google.com/group/microsoft.public.windowsxp.general/msg/a066ae41add7dd2b
-
When you try to import video files in Movie Maker I get the message; M2U00017. MPG could not be imported. An interface has too many methods to fire events from
-What this means and how do I fix it so I can import video files to edit?
When you try to import video files in Movie Maker I get the message; M2U00017. MPG could not be imported. An interface has too many methods to fire events from
-What this means and how do I fix it so I can import video files to edit?
=======================================
Movie Maker has problems with the .mpg files... best bet would be
to convert the .mpg files before importing the .wmv format.Several formats are apparently compatible with
Movie Maker, but the most reliable choices are:Photos - bmp
Video - wmv or dv - avi
Music - wma, wav, .wmvSee the following article:
Movie Maker 2 - Import MPEG files
http://www.Papajohn.org/mm2-importing-video-MPEG2.htmlThe following freeware can convert:
(FWIW... it's always a good idea to create a system)
Restore point before installing software or updates)Format Factory
http://www.pcfreetime.com/
(FWIW... you can uncheck
all the boxes on the last screen)After downloading and installing Format Factory...
Open the program and choose an output folder...
(this is where you will find your files when they are
converted)Drag and drop your video clips on the main screen...
Select "At?" / OK...
(the? is the format of your choice)Click on... Beginning... in the toolbar...
That should do it...
Good luck...
John Inzer - MS - MVP - digital media experience
-
Where can I get the service pack for Windows Vista updates?
just renovated Vista then how to pass if thiers no upgrade now
If I carnt get vista service pack 1, i carnt upgrade to 2
How am Hi surpose upgrading then you've got a service pack1 but its for a language of muli 64 bit for 2 computors. can I use that so I can up grade to service pack 2
Hello
You can use the stand-alone version to install SP1
What version of bits you have; 32-bit or 64-bit?
Click Start > right click on computer > left click on properties > it will tell you it.
Here are the links to direct download for SP1
Vista Service Pack 1 32-bit: http://www.microsoft.com/en-us/download/details.aspx?id=30
Vista Service Pack 1 64-bit: http://www.microsoft.com/en-us/download/details.aspx?id=21299
See you soon.
-
VAIO laptop
New hard drive mounted, didn't save lost all devices sony and Microsoft word. Still have the product that was supplied with the laptop key. Can I get this without having to buy new?To restore the software preinstalled on the computer, or to install disks:
Contact the OEM computer manufacturer and ask them to send you an installation to your computer disk - they may charge a small fee. Contact information for the manufacturer of your computer can be found here:
http://support.Microsoft.com/GP/oemphone/
Sony support:
http://eSupport.Sony.com/ -
Passport for BlackBerry blackBerry Passport Silver Edition - how to get the language pack
Hello
I'll buy the SIlver Edition of uk.blackberry.com Passport and would like to know how to get the language pack (Hungarian).
Thanks a lot for your help.
Klaudia
the language of your choice in the value parameters
-
How to make HTTP GET request socket?
I want to use socket make HTTP GET, but I always got the error 501 return.
Result:
501 method not implemented
Method not implemented
to / index.html unsupported.
Apache/2.0.52 (CentOS) Server at li43-231.members.linode.com Port 80
Code:
streamConnection =
(StreamConnection) Connector.Open (getURL (3) + APN_STR, Connector.READ_WRITE);
create DataOuputStream on the top of the socket connection
outputStream = streamConnection.openOutputStream ();
dataOutputStream = new DataOutputStream (outputStream);
Send the HTTP request
dataOutputStream.writeChars ("GET/index.html http/2.0\n");
dataOutputStream.writeChars ("host: badev.liveblockauctions.com\n");
dataOutputStream.writeChars("User-Agent:BlackBerry/3.2.1\n");
dataOutputStream.writeChars("Content-Language:en-US\n\n");dataOutputStream.flush ();
create DataInputStream on top of the socket connection
inputStream = streamConnection.openInputStream ();
dataInputStream = new DataInputStream (inputStream);
retrieve the content of the requested server Web page
int inputChar;
int size = 0;
StringBuffer results = new StringBuffer();
While ((inputChar = dataInputStream.read ())! = - 1) {}
size ++;
Results.Append ((Char) inputChar);
}JDE 4.6 and blackberry "BOLD".
Any suggestion?
Thank you very much!
-
Failed to get component of the arbitrator
When I click on Viewer call in the warehouse of cisco unity tool, I get the following error... Failed to get component of the arbitrator... any thoughts
The connected account is associated with any subscriber?
Try UnityInstall
-
I tried to install Family Tree Maker and get 1310 error writing to file: BCL. EasyConverterLiB.Interop.dll have no idea what to do.
Hello
1. how you try to install this program?
I suggest you to set up your computer in a clean boot state, and check to see if the same problem happens.
By setting your boot system minimum state helps determine if third-party applications or startup items are causing the problem.
How to troubleshoot a problem by performing a clean boot in Windows Vista or Windows 7:
http://support.Microsoft.com/kb/929135Note: After the boot minimum troubleshooting step, follow step 7 in the link provided to return the computer to a Normal startup mode.
If the problem persists, then contact family tree click the link below:
http://www.familytreemaker.com/support/contact
Hope this information is useful.
-
Hello! Has bought the photos but they have still the watermark Adobe & the free also, how I can get them without the watermark?
Follow the steps in these screenshots: I downloaded my 10 free images and they all have the Adobe watermark on them, so I can't use them. Why do they have a watermark on them?
-
I have the disc to download Adobe Photoshop CS2, but I do not have a CD-ROM on my laptop, is it possible that I can get it without a CD?
CS2 (or earlier version) activation server has disappeared, then read below
You MUST use the special number on the page, not your original serial number
l http://helpx.adobe.com/x-productkb/Policy-Pricing/Creative-Suite-2-activation-end-Life.htm
NOTE that CS2 will not install on a Mac "modern", and when you install the special version of the PPro2 on a Win7 or Win8 or Win10 computer, you may need to right click on the program icon and select Windows XP compatibility in the popup of option
... AND Vista problems https://forums.adobe.com/thread/416347
Maybe you are looking for
-
How recover Equium L40-10 X?
Hello I'm trying to reboot my computer to factory settings do not know how to do this I need a floppy or there at - it something built into the laptop. Any help much appreciated. I have an Equium L40-10 X. Thank you
-
My cursor is unresponsive and sometimes beach balls.
My cursor stops responding. It is not Frost simply does not work and I can't scroll. Also, sometimes I get a beachball. Here is my information. I have a lot of Red! EtreCheck version: 2.7.7 (237) Report generated 2016-01-24 15:49:52 Download Etre
-
change suddenly in the Task Manager
All of a sudden (nothing has been installed), changed the Task Manager window. It can now be minimized and right-click on its process in the bar tasks generates no response. I can still close by closing all windows, but if I open any other applicat
-
Want to copy and paste the names of files only, not the content
I have organized hundreds of files in several folders of dozens and that you must first create a list or map of all files. I want only the names of files, not other thing. I found some freeware that seems designed to do this, but am reluctant to do
-
Windows 7 does not connect to Time Capsule
I have 2 computers connected to Apple's Time Capsule. I have the HP laptop with Windows Vista Home Premium SP1 with all updates trendy top of x 64 and it is able to connect to the Wi - Fi router part and connect to the part of the external hard driv