Table package in java

Package javax.swing.table

Provides classes and interfaces for dealing with javax.swing.JTable . JTable is Swing’s grid or tabular view for constructing user interfaces for tabular data structures inside an application. Use this package if you want control over how tables are constructed, updated, and rendered, as well as how data associated with the tables are viewed and managed.

Note: Most of the Swing API is not thread safe. For details, see Concurrency in Swing, a section in The Java Tutorial.

Provides a set of «lightweight» (all-Java language) components that, to the maximum degree possible, work the same on all platforms.

This abstract class provides default implementations for most of the methods in the TableModel interface.

This is an implementation of TableModel that uses a Vector of Vectors to store the cell value objects.

This interface defines the method required by any object that would like to be a renderer for cells in a JTable .

A TableColumn represents all the attributes of a column in a JTable , such as width, resizability, minimum and maximum width.

Читайте также:  Public html php ini

The TableModel interface specifies the methods the JTable will use to interrogate a tabular data model.

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Package javax.swing.table

This interface defines the method any object that would like to be an editor of values for components such as JListBox , JComboBox , JTree , or JTable needs to implement.

This interface defines the method required by any object that would like to be a renderer for cells in a JTable .

The TableModel interface specifies the methods the JTable will use to interrogate a tabular data model.

This abstract class provides default implementations for most of the methods in the TableModel interface.

This is an implementation of TableModel that uses a Vector of Vectors to store the cell value objects.

A TableColumn represents all the attributes of a column in a JTable , such as width, resizability, minimum and maximum width.

Package javax.swing.table Description

Provides classes and interfaces for dealing with javax.swing.JTable . JTable is Swing’s grid or tabular view for constructing user interfaces for tabular data structures inside an application. Use this package if you want control over how tables are constructed, updated, and rendered, as well as how data associated with the tables are viewed and managed.

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Источник

Guide to Guava Table

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Connect your cluster and start monitoring your K8s costs right away:

We rely on other people’s code in our own work. Every day.

It might be the language you’re writing in, the framework you’re building on, or some esoteric piece of software that does one thing so well you never found the need to implement it yourself.

The problem is, of course, when things fall apart in production — debugging the implementation of a 3rd party library you have no intimate knowledge of is, to say the least, tricky.

Lightrun is a new kind of debugger.

It’s one geared specifically towards real-life production environments. Using Lightrun, you can drill down into running applications, including 3rd party dependencies, with real-time logs, snapshots, and metrics.

Learn more in this quick, 5-minute Lightrun tutorial:

announcement - icon

Slow MySQL query performance is all too common. Of course it is. A good way to go is, naturally, a dedicated profiler that actually understands the ins and outs of MySQL.

The Jet Profiler was built for MySQL only, so it can do things like real-time query performance, focus on most used tables or most frequent queries, quickly identify performance issues and basically help you optimize your queries.

Critically, it has very minimal impact on your server’s performance, with most of the profiling work done separately — so it needs no server changes, agents or separate services.

Basically, you install the desktop application, connect to your MySQL server, hit the record button, and you’ll have results within minutes:

announcement - icon

DbSchema is a super-flexible database designer, which can take you from designing the DB with your team all the way to safely deploying the schema.

The way it does all of that is by using a design model, a database-independent image of the schema, which can be shared in a team using GIT and compared or deployed on to any database.

And, of course, it can be heavily visual, allowing you to interact with the database using diagrams, visually compose queries, explore the data, generate random data, import data or build HTML5 database reports.

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Connect your cluster and start monitoring your K8s costs right away:

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

We’re looking for a new Java technical editor to help review new articles for the site.

1. Overview

In this tutorial, we’ll show how to use the Google Guava’s Table interface and its multiple implementations.

Guava’s Table is a collection that represents a table like structure containing rows, columns and the associated cell values. The row and the column act as an ordered pair of keys.

2. Google Guava’s Table

Let’s have a look at how to use the Table class.

2.1. Maven Dependency

Let’s start by adding Google’s Guava library dependency in the pom.xml:

 com.google.guava guava 31.0.1-jre 

The latest version of the dependency can be checked here.

2.2. About

If we were to represent Guava’s Table using Collections present in core Java, then the structure would be a map of rows where each row contains a map of columns with associated cell values.

Table represents a special map where two keys can be specified in combined fashion to refer to a single value.

It’s similar to creating a map of maps, for example, Map>. Table would be also a perfect way of representing the Battleships game board.

3. Creating

You can create an instance of Table in multiple ways:

    Using the create method from the class HashBasedTable which uses LinkedHashMap internally:

Table universityCourseSeatTable = HashBasedTable.create();
Table universityCourseSeatTable = TreeBasedTable.create(); 
List universityRowTable = Lists.newArrayList("Mumbai", "Harvard"); List courseColumnTables = Lists.newArrayList("Chemical", "IT", "Electrical"); Table universityCourseSeatTable = ArrayTable.create(universityRowTable, courseColumnTables); 
Table universityCourseSeatTable = ImmutableTable. builder() .put("Mumbai", "Chemical", 120).build(); 

4. Using

Let’s start with a simple example showing the usage of Table.

4.1. Retrieval

If we know the row key and the column key then we can get the value associated with the row and the column key:

@Test public void givenTable_whenGet_returnsSuccessfully() < TableuniversityCourseSeatTable = HashBasedTable.create(); universityCourseSeatTable.put("Mumbai", "Chemical", 120); universityCourseSeatTable.put("Mumbai", "IT", 60); universityCourseSeatTable.put("Harvard", "Electrical", 60); universityCourseSeatTable.put("Harvard", "IT", 120); int seatCount = universityCourseSeatTable.get("Mumbai", "IT"); Integer seatCountForNoEntry = universityCourseSeatTable.get("Oxford", "IT"); assertThat(seatCount).isEqualTo(60); assertThat(seatCountForNoEntry).isEqualTo(null); >

4.2. Checking for an Entry

We can check the presence of an entry in a Table based on:

Let’s see how to check for the presence of an entry:

@Test public void givenTable_whenContains_returnsSuccessfully() < TableuniversityCourseSeatTable = HashBasedTable.create(); universityCourseSeatTable.put("Mumbai", "Chemical", 120); universityCourseSeatTable.put("Mumbai", "IT", 60); universityCourseSeatTable.put("Harvard", "Electrical", 60); universityCourseSeatTable.put("Harvard", "IT", 120); boolean entryIsPresent = universityCourseSeatTable.contains("Mumbai", "IT"); boolean courseIsPresent = universityCourseSeatTable.containsColumn("IT"); boolean universityIsPresent = universityCourseSeatTable.containsRow("Mumbai"); boolean seatCountIsPresent = universityCourseSeatTable.containsValue(60); assertThat(entryIsPresent).isEqualTo(true); assertThat(courseIsPresent).isEqualTo(true); assertThat(universityIsPresent).isEqualTo(true); assertThat(seatCountIsPresent).isEqualTo(true); >

4.3. Removal

We can remove an entry from the Table by supplying both the row key and column key:

@Test public void givenTable_whenRemove_returnsSuccessfully() < TableuniversityCourseSeatTable = HashBasedTable.create(); universityCourseSeatTable.put("Mumbai", "Chemical", 120); universityCourseSeatTable.put("Mumbai", "IT", 60); int seatCount = universityCourseSeatTable.remove("Mumbai", "IT"); assertThat(seatCount).isEqualTo(60); assertThat(universityCourseSeatTable.remove("Mumbai", "IT")). isEqualTo(null); > 

4.4. Row Key to Cell Value Map

We can get a Map representation with the key as a row and the value as a CellValue by providing the column key:

@Test public void givenTable_whenColumn_returnsSuccessfully() < TableuniversityCourseSeatTable = HashBasedTable.create(); universityCourseSeatTable.put("Mumbai", "Chemical", 120); universityCourseSeatTable.put("Mumbai", "IT", 60); universityCourseSeatTable.put("Harvard", "Electrical", 60); universityCourseSeatTable.put("Harvard", "IT", 120); Map universitySeatMap = universityCourseSeatTable.column("IT"); assertThat(universitySeatMap).hasSize(2); assertThat(universitySeatMap.get("Mumbai")).isEqualTo(60); assertThat(universitySeatMap.get("Harvard")).isEqualTo(120); > 

4.5. Map Representation of a Table

@Test public void givenTable_whenColumnMap_returnsSuccessfully() < TableuniversityCourseSeatTable = HashBasedTable.create(); universityCourseSeatTable.put("Mumbai", "Chemical", 120); universityCourseSeatTable.put("Mumbai", "IT", 60); universityCourseSeatTable.put("Harvard", "Electrical", 60); universityCourseSeatTable.put("Harvard", "IT", 120); Map> courseKeyUniversitySeatMap = universityCourseSeatTable.columnMap(); assertThat(courseKeyUniversitySeatMap).hasSize(3); assertThat(courseKeyUniversitySeatMap.get("IT")).hasSize(2); assertThat(courseKeyUniversitySeatMap.get("Electrical")).hasSize(1); assertThat(courseKeyUniversitySeatMap.get("Chemical")).hasSize(1); > 

4.6. Column Key to Cell Value Map

We can get a Map representation with the key as a column and the value as a CellValue by providing row key:

@Test public void givenTable_whenRow_returnsSuccessfully() < TableuniversityCourseSeatTable = HashBasedTable.create(); universityCourseSeatTable.put("Mumbai", "Chemical", 120); universityCourseSeatTable.put("Mumbai", "IT", 60); universityCourseSeatTable.put("Harvard", "Electrical", 60); universityCourseSeatTable.put("Harvard", "IT", 120); Map courseSeatMap = universityCourseSeatTable.row("Mumbai"); assertThat(courseSeatMap).hasSize(2); assertThat(courseSeatMap.get("IT")).isEqualTo(60); assertThat(courseSeatMap.get("Chemical")).isEqualTo(120); > 

4.7. Get Distinct Row Key

We can get all the row keys from a table using the rowKeySet method:

@Test public void givenTable_whenRowKeySet_returnsSuccessfully() < TableuniversityCourseSeatTable = HashBasedTable.create(); universityCourseSeatTable.put("Mumbai", "Chemical", 120); universityCourseSeatTable.put("Mumbai", "IT", 60); universityCourseSeatTable.put("Harvard", "Electrical", 60); universityCourseSeatTable.put("Harvard", "IT", 120); Set universitySet = universityCourseSeatTable.rowKeySet(); assertThat(universitySet).hasSize(2); > 

4.8. Get Distinct Column Key

We can get all column keys from a table using the columnKeySet method:

@Test public void givenTable_whenColKeySet_returnsSuccessfully() < TableuniversityCourseSeatTable = HashBasedTable.create(); universityCourseSeatTable.put("Mumbai", "Chemical", 120); universityCourseSeatTable.put("Mumbai", "IT", 60); universityCourseSeatTable.put("Harvard", "Electrical", 60); universityCourseSeatTable.put("Harvard", "IT", 120); Set courseSet = universityCourseSeatTable.columnKeySet(); assertThat(courseSet).hasSize(3); > 

5. Conclusion

In this tutorial, we illustrated the methods of the Table class from the Guava library. The Table class provides a collection that represents a table like structure containing rows, columns and associated cell values.

The code belonging to the above examples can be found in the GitHub project – this is a Maven-based project, so it should be easy to import and run as is.

announcement - icon

Slow MySQL query performance is all too common. Of course it is. A good way to go is, naturally, a dedicated profiler that actually understands the ins and outs of MySQL.

The Jet Profiler was built for MySQL only, so it can do things like real-time query performance, focus on most used tables or most frequent queries, quickly identify performance issues and basically help you optimize your queries.

Critically, it has very minimal impact on your server’s performance, with most of the profiling work done separately — so it needs no server changes, agents or separate services.

Basically, you install the desktop application, connect to your MySQL server, hit the record button, and you’ll have results within minutes:

Источник

Package javax.swing.table

Provides classes and interfaces for dealing with javax.swing.JTable . JTable is Swing’s grid or tabular view for constructing user interfaces for tabular data structures inside an application. Use this package if you want control over how tables are constructed, updated, and rendered, as well as how data associated with the tables are viewed and managed.

Note: Most of the Swing API is not thread safe. For details, see Concurrency in Swing, a section in The Java Tutorial.

This interface defines the method any object that would like to be an editor of values for components such as JListBox , JComboBox , JTree , or JTable needs to implement.

This interface defines the method required by any object that would like to be a renderer for cells in a JTable .

The TableModel interface specifies the methods the JTable will use to interrogate a tabular data model.

This abstract class provides default implementations for most of the methods in the TableModel interface.

This is an implementation of TableModel that uses a Vector of Vectors to store the cell value objects.

A TableColumn represents all the attributes of a column in a JTable , such as width, resizability, minimum and maximum width.

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Оцените статью